In the code below, I am attempting to create a mutator method that alters the input List. When I write the same code, and do not use a method, it works and prints Mouse
. However, when I create the mutate method below, House
is printed rather than Mouse
. Please explain why the line inputList = temp
isn't working.
public class Demo {
public static void main(String[] args) {
List<String> list = new ArrayList<String>();
list.add("House");
mutate(list);
System.out.println(list);
}
public static void mutate(List<String> inputList){
List<String> temp = new ArrayList<String>();
temp.add("Mouse");
inputList = temp;
}
}