Hahaha, how do you implement the function of comparing whether the elements in two arrays are the same in Java? See the simplest method below:
Copy the code code as follows:
import java.util.Arrays;
public class Test {
/**
* Java compares whether the elements in two arrays are the same
*/
public static void main(String[] args) {
String [] array1 = {"1","2","3"};
String [] array2 = {"3","2","1"};
Arrays.sort(array1);
Arrays.sort(array2);
if (Arrays.equals(array1, array2)) {
System.out.println("The elements in the two arrays have the same value");
} else {
System.out.println("The elements in the two arrays have different values");
}
}
}