I am trying to compare the first element in an arraylist to the rest of the elements.
Then comparing the second element of the arraylist to the rest of the elements and so on until
the end of the arraylist.
The code is as below:
ArrayList<String> a = new ArrayList<String>();
a.add("G1");
a.add("G2");
a.add("G3");
a.add("G1");
System.out.println(a.size());
for(int i = 0; i<a.size(); i++){
for(int j = 0; j<a.size(); j++){
if(a.get(i) == a.get(j))
System.out.println("Element: " + a.get(i)+ " at " + i + " and " + "Element: "+ a.get(j)+ " at " + j);
}
}
String.equals()method to compare string