Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (7k points)

How to compare two integer arrays in Java?

1 Answer

0 votes
by (13.1k points)

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);

    }

Want to learn Java? Check out the Java certification from Intellipaat. 

Related questions

0 votes
1 answer
0 votes
1 answer
+1 vote
2 answers
0 votes
1 answer
0 votes
1 answer
asked Sep 19, 2019 in Java by Anvi (10.2k points)

Browse Categories

...