import java.util.Collection; import java.util.HashMap; import java.util.Map; import java.util.Set; public class Test { public static void main(String[] args) { Map<String, Object> map = new HashMap<String, Object>(); map.put("hah", 123); map.put("aa", 12314); map.put("xu", "123"); // map.clear(); Object object = map.get("hah"); System.out.println("map.get:" + object); boolean containsKey = map.containsKey("hah"); System.out.println("map.containsKey:" + containsKey); int hashCode = map.hashCode(); System.out.println("map.hashCode:" + hashCode); boolean empty = map.isEmpty(); System.out.println("map.isEmpty:" + empty); Set<String> keySet = map.keySet(); System.out.println("map.keySet:" + keySet); Object remove = map.remove("xu"); System.out.println("map.keySet:" + map.keySet()); int size = map.size(); System.out.println("map.size:" + size); Collection<Object> values = map.values(); System.out.println("map.values:" + values); Set<String> keySet2 = map.keySet(); System.out.println("map.keySet2:" + keySet2); Map<String, Object> map1 = new HashMap<String, Object>(); map1.put("aa", "123"); map1.put("bb", 234); Map<String, Object> map2 = new HashMap<String, Object>(); map2.put("aa", "123"); map2.put("bb", 234); boolean equals2 = map1.equals(map2); System.out.println("map2.equals:" + equals2); } }
map.get:123 map.containsKey:true map.hashCode:163837 map.isEmpty:false map.keySet:[aa, hah, xu] map.keySet:[aa, hah] map.size:2 map.values:[12314, 123] map.keySet2:[aa, hah] map2.equals:true
时间: 2024-10-08 21:35:50