首页 > 代码库 > Map 基础用法
Map 基础用法
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
Map 基础用法
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。