So the below method I'm aware causes both variables to point to the same object, but if I did want to find the simplest method to has ArrayList s2 exactly the same as s1, how would I do this?
public static void main(String[] args) {
ArrayList<String> s1 = new ArrayList<String>();
for (int i = 1; i <= 3; i++) {
s1.add(""+i);
}
ArrayList<String> s2 = s1;
}
forloop. Maybe the JVM will optimize that out, but I'd useInteger.toString(i)instead of""+ito get the String representation of an int.