How to check if an array has specific data in a specific order

I need to check if an array exists

int arr2[4];

has specific data in a specific order. In my case, I need to check if the arr2[4];following data has: 2,3,3,5. I tried this, but to no avail:

 if (arr2 = {2,3,3,5}){
    //whatever
 }

Otherwise, I suppose I can just create an array "arr3" with data 2,3,3,5, and then check if arr2 = arr3 ... I don't know. Maybe I can't even do that!

I will be very happy if someone can help me in this matter!

+3
source share
1 answer

You must use Array.equals.

if (Arrays.equals(myArray, new int[] {2,3,3,5}) {
    // do this!
}
+4
source

Source: https://habr.com/ru/post/1791858/


All Articles