Back
How to compare two integer arrays in Java?
You can try this:
public static void compareArrays(int[] array1, int[] array2) { boolean b = true; if (array1 != null && array2 != null){ if (array1.length != array2.length) b = false; else for (int i = 0; i < array2.length; i++) { if (array2[i] != array1[i]) { b = false; } } }else{ b = false; } System.out.println(b); }
public static void compareArrays(int[] array1, int[] array2) {
boolean b = true;
if (array1 != null && array2 != null){
if (array1.length != array2.length)
b = false;
else
for (int i = 0; i < array2.length; i++) {
if (array2[i] != array1[i]) {
}
}else{
System.out.println(b);
Want to learn Java? Check out the Java certification from Intellipaat.
31k questions
32.8k answers
501 comments
693 users