如何在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}热门推荐
1 狗狗技能训练
5 如何训练狗狗笑
6 狗狗训练排便
9 狗狗响片训练
10 如何训练狗狗不捡食
11 狗狗尿训练
12 怎么训练狗狗找东西
13 狗狗训练站立
14 狗狗训练飞盘
15 鞍山狗狗训练
16 怎样训练泰迪狗狗谢谢
17 狗狗外出训练
18 怎么训练金毛狗狗大小便