import java.util.ArrayList;import java.util.HashMap;import java.util.HashSet;import java.util.List;import java.util.Map;import java.util.Set;public class MapTest { public static void main(String[] args) { Map m =new HashMap(); m.put("1", 2); Object i = m.get("1"); System.out.println(m.put("1", 3)); System.out.println(m.get("1")); Set set = new HashSet(); set.add("5"); System.out.println(set.add("5")); List li = new ArrayList(); set.add("6"); System.out.println(set.add("6")); System.out.println("----Map------------------------"); m.put(new T("A"), "d"); m.put(new T("A"), "f"); m.put(new T("A"), "g"); System.out.println("----set------------------------"); set.add(new T("A")); set.add(new T("A")); set.add(new T("A")); System.out.println("----list------------------------"); li.add(new T("A")); li.add(new T("A")); li.add(new T("A")); }}class T{ private String hashcode; public T(String hsCode){ hashcode = hsCode; } @Override public int hashCode() { // TODO Auto-generated method stub System.out.println("hashcode Function "); return hashcode.hashCode(); } @Override public boolean equals(Object obj) { System.out.println("equals Function "); // TODO Auto-generated method stub return super.equals(obj); }}
23falsefalse----Map------------------------hashcode Function hashcode Function equals Function hashcode Function equals Function equals Function ----set------------------------hashcode Function hashcode Function equals Function hashcode Function equals Function equals Function ----list------------------------