Hi,
I have code like this,
public void method1(){
ArrayList<String> list=new ArrayList<String>();
list.add("A");
list.add("C");
list.add("D");
for(int i=0;i<list.size();i++){
if(i==0){
new Test().addB(list);
}
}
System.out.println(list)
}
public void addB(ArrayList<String> list1)
{
list1.add(1,"B");
System.out.println(list1);
}
output:
List1: A,B,C,D
List : A,B,C,D
I Expected this Result:
List1: A,B,C,D
List : A,C,D
Why List1 is overridding to list? Kindly share about this.