我有這個問題,但我不知道它在哪裏出錯。與陣列相關
int[] first = new int[2];
first[0] = 3;
first[1] = 7;
int[] second = new int[2];
second[0] = 3;
second[1] = 7;
// print the array elements
System.out.println("first = [" + first[0] + ", " + first[1] + "]");
System.out.println("second = [" + second[0] + ", " + second[1] + "]");
// see if the elements are the same
if (first[] = second[]) {
System.out.println("They contain the same elements.");
} else {
System.out.println("The elements are different.");
}
預期出放應該是這樣的,例如:
first = [3, 7]
second = [3, 7]
They contain the same elements.
評論http://stackoverflow.com/questions/8777257/equals-vs-arrays-equals-in-java –