如何在Java 9的JShell中实现HashMap,LinkedHashMap和TreeMap?
Map接口指定一个合约,以键/值 对的形式实现元素的集合。实现Map 接口的Java集合类是HashMap,LinkedHashMap和TreeMap。
片段1
jshell> HashMap<String, Integer> hashMap = new HashMap<>();
hashMap ==> {}
jshell> hashMap.put("Adithya", 101);
$2 ==> null
jshell> hashMap.put("Jai", 102);
$3 ==> null
jshell> hashMap.put("Chaitanya", 103);
$4 ==> null
jshell> hashMap.put("Ravi", 104);
$5 ==> null
jshell> hashMap
hashMap ==> {Chaitanya=103, Jai=102, Ravi=104, Adithya=101}我n中的下面的代码片断,的元素LinkedHashMap的 已经存储在插入 顺序。
片段3
jshell> TreeMap<String, Integer> treeMap = new TreeMap<>();
treeMap ==> {}
jshell> treeMap.put("Raj", 101);
$14 ==> null
jshell> treeMap.put("Pavan", 102);
$15 ==> null
jshell> treeMap.put("Arjun", 103);
$16 ==> null
jshell> treeMap.put("Manoj", 104);
$17 ==> null
jshell> treeMap
treeMap ==> {Arjun=103, Manoj=104, Pavan=102, Raj=101}热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短