Collection holds value as a refernce in java
Value as a Reference example : Here we are fecthing a list from a collection and updating this which leads to automatic update of Map because numList is directly referring to testmap. ----------------------------------- public class ValueAsReference{ enum EvenOdd{ EVEN,ODD } public static void main(String ... arg){ Map<String,List<String>> testmap=new HashMap<String, List<String>>(); for(int i=0;i<20;i++){ String key=""; if(i%2 ==0){ key=""+EvenOdd.EVEN; }else{ key=""+EvenOdd.ODD; } List<String> numList=testmap.get(key); if(numList==null){ numList=new ArrayList<String>(); numList.add("i="+i); testmap.put(key, numList); }else{ numList.add("i="+i); } } for(String key : testmap.keySet()){ System.out.println("key : "+key); System.out.println(testmap.get(key)); } ...