public static void main(String [] args){
ArrayList<String> list1 = new ArrayList<String>();
list1.add("ABC");
list1.add("123");
ArrayList<String> list2 = method(list1);
list2.add("ABC");
list1.add("123");
System.out.println(list1);
System.out.println(list2);
}
private static ArrayList<String> method(ArrayList<String> list) {
ArrayList<String> result = list;
result.remove("123");
return result;
}
Could anyone explain this code to me? why it gives me the same result in list1 & list2..
thank you,