0

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?

Vikas Gupta
  • 10,779
  • 4
  • 35
  • 42
Trevor
  • 11
  • 4

1 Answers1

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