如何在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 婆婆66岁祝福语简短
13 今天孩子高考祝福语简短
14 送彩票生日祝福语简短
15 分别祝福语简短情话英文
16 画室揭牌仪式祝福语简短
17 女友妈妈生日祝福语简短
18 离别赠言离职祝福语简短