For example, if an arraylist holds the values [1, 2, 3], is there any way to check if they are in that order using indexOf or any other way?
Asked
Active
Viewed 24 times
0
-
Are you asking if there is a way to check if a list is sorted? – gariepy Jan 13 '16 at 16:03
-
No, I am wondering if you can check if an arraylist has certain values in certain places of an array. – Trevor Jan 13 '16 at 16:15
1 Answers
0
Just compare the order and the array with a for-loop:
public boolean isArrayInOrder(int[] array, int... order) {
if(array.length == order.length) {
for(int i = 0; i < array.length; ++i) {
if(array[i] != order[i]) return false;
}
return true;
}
return false;
}

ZetQ
- 51
- 4