To compare two string arrays in Java, call the
Arrays.equals
method.Arrays.equals
compares elements of arrays at same positions using the equals
method:
String[] array1 = new String[] { "Hello", "World", "!!!" };
String[] array2 = new String[] { "Hello", "World" };
Arrays.equals(array1, array1); // true
Arrays.equals(array1, array2); // false