I have created a List and added 2 elements to it. I pass this List to a method and initialized the list to new ArrayList()
.
When the method returns I print the size of list but it still shows 2.
public class ValueChange {
public void fun(List<Integer> l1){
l1=new ArrayList<Integer>();
}
public static void main(String[] args){
List<Integer> l1=new ArrayList<Integer>();
l1.add(5);
l1.add(6);
System.out.println("Before = "+l1.size());
ValueChange vc=new ValueChange();
vc.fun(l1);
System.out.println("After = "+l1.size());
}
}