If java is Pass By value Only Than why here its changing the value in list
I tried with Object also
public static void main(String[] args) {
List<Integer> list = new ArrayList<>();
list.add(12);
list.add(15);
list.add(45);
addExternally(list);
ListIterator<Integer>
iterator = list.listIterator();
while(iterator.hasNext()) {
System.out.println("Value is : "
+ iterator.next());
}
}
private static void addExternally(List<Integer> list) {
list.add(11);
list.add(12);
}
it should not take the changes from addExternally method but its taking why