Hi, please look at the code below:-
---------------------------------
public class a { // comparing 2 arrays
public static void main (
String args[]) {
int array1 [] = {1,2}; // array1
int array2 [] = {1,2}; // array2
if (array1 == array2) System.out.println("same");
} // ~main()
} // ~class
---------------------------------
1. Why doesn't it print same?
2. Also, how do I compare these 2 arrays so that I can make it print same?
3. Ideally, I want to compare 2 elements AT THE SAME TIME, eg 2 for loops won't work as they only let me compare ONE element at a time - I need to be able to compare 2 (& more) elements at a time - Does anyone know how to do this?
Any help with this problem will be greatly appreciated. Many thanks.