import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Random; public class Hash { public static void main(String[] args) { testHashMap(); } public static void testHashMap() { Random r = new Random(); HashMap map = new HashMap(); map.put("one",r.nextInt(10)); map.put("two",r.nextInt(10)); map.put("three",r.nextInt(10)); System.out.println("map"+map); Iterator iterator = map.entrySet().iterator(); while (iterator.hasNext()){ Map.Entry entry = (Map.Entry) iterator.next(); System.out.println(entry); } System.out.println("size:"+map.size()); System.out.println("contain key one:"+ map.containsKey("one")); System.out.println("contain value 4:"+ map.containsValue(2)); map.remove("four"); map.clear(); System.out.println("map是否为空:"+map.isEmpty()); } }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)