No you can't implement it like that. Same with arrays. Pass-reference-by-value problem, like the others explained already.
If you want the lists to swap their content, then you have to clear and copy:
public static void swapList(List<Integer> list1, List<Integer> list2){
List<Integer> tmpList = new ArrayList<Integer>(list1);
list1.clear();
list1.addAll(list2);
list2.clear();
list2.addAll(tmpList);
}
Some additional thoughts:
List<Integer> list1 = getList1Magic();
List<Integer> list2 = getList2Magic();
if (isSwapReferences()) {
// this does not affect the actual lists
List<Integer> temp = list2;
list2 = list1;
list1 = temp;
} else if (isSwapListContent()) {
// this modifies the lists
swapList(list1, list2); // method from above
}
The swap strategy depends on your requirements. First block has a local effect, second block a global one.