There are lot of discussions in stackoverflow regarding pass by value and pass by reference. But i want to know what is happening in the following scenario? This page says java is pass by value. Is Java "pass-by-reference" or "pass-by-value"?.
In case of following code, the the element is removed from the removeElement method , it is removing the 5th element from list when i print the list.
public class Load {
public static void main(String[] args) {
ArrayList<Integer> list = new ArrayList<Integer>();
list.addAll(Arrays.asList(1,1,2,3,5,5,13,21));
removeElement(list);
System.out.println(list);
}
public static void removeElement(List<Integer> list){
list.remove(5);//removes element at index 5
}
}
The output of the program is [1, 1, 2, 3, 5, 13, 21]
.
Can somebody explain how this is pass by value rather than pass by reference?