Array Utils Methods Flashcards

1
Q

Reverse an array

A
int[] intArray = { 1, 2, 3, 4, 5 };
ArrayUtils.reverse(intArray);
System.out.println(Arrays.toString(intArray));
//[5, 4, 3, 2, 1]
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Remove element of an array

A

int[] intArray = { 1, 2, 3, 4, 5 };
int[] removed = ArrayUtils.removeElement(intArray, 3);//create a new array
System.out.println(Arrays.toString(removed));

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Concatenate two arrays

A
int[] intArray = { 1, 2, 3, 4, 5 };
int[] intArray2 = { 6, 7, 8, 9, 10 };
// Apache Commons Lang library
int[] combinedIntArray = ArrayUtils.addAll(intArray, intArray2);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly