开发者

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

开发者 https://www.devze.com 2023-02-10 10:27 出处:网络
I need to test if an array int arr2[4]; has specific data in a specific order. In my开发者_StackOverflow case I need to test if arr2[4]; has the following data: 2,3,3,5. I tried this but to no avai

I need to test if an array

int arr2[4];

has specific data in a specific order. In my开发者_StackOverflow case I need to test if arr2[4]; has the following data: 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 test if arr2 = arr3... I don't know. Maybe I can't even do that!

Will be very glad if someone can help me in this matter!


You should use Array.equals.

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

精彩评论

暂无评论...
验证码 换一张
取 消