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!
}
精彩评论