Comparing Arrays in Java

This Java tutorial shows the quick and easy way to compare arrays in Java. In Java 1.2, Sun added the Arrays class in the java.util package. This class provides a number of array utility methods including methods to compare two arrays.

The Arrays.equals() method will compare two arrays. This method will compare number of elements in the array as well as the actual data in the array.

Below is sample code for comparing two arrays in Java:

String[] arrayOne = { "a", "b", "c" };
String[] arrayTwo = { "d", "e", "f" };

boolean equals = Arrays.equals(arrayOne, arrayTwo);


0 comments:

Post a Comment