Java-Map集合的學習
阿新 • • 發佈:2018-06-23
nmap 1-1 TP size key mage In pad ID
1. Map
1.1. map中的方法
1.2. Map.Entry
對於集合來講,就是把kye-value的數據保存在了Map.Entry的實例之後,再在Map集合中插入了一個Map.Entry的實例化對象
Map.Entry一般用於輸出集合
1.3. Map接口的常用子類
1.4. HashTable和HashMap區別
1.5. Map的標準輸出(2個)
方案一:
方案二:
package com.ftl; import java.util.Collection; import java.util.Iterator; import java.util.Map; importjava.util.Map.Entry; import java.util.Set; import java.util.TreeMap; public class Test2018 { public static void main(String[] args) { Map<String, String> map = new TreeMap<>(); map.put("Hello", "world"); map.put("Hello1", "world1"); map.put("Hello2", "world2"); map.put("Hello3", "world3"); String str = map.get("Hello"); Set<String> set = map.keySet(); Collection<String> values = map.values(); Iterator<String> iterator = set.iterator(); Iterator<String> iter = values.iterator(); System.out.println("\nforeach方法:"); for (String s : values) { System.out.print(s + "、"); } System.out.println("\nIterator方法:"); while (iterator.hasNext()) { System.out.print(iterator.next() + "、"); } System.out.println("\nMap的標準輸出_1(Map.entrySet):"); Set<Entry<String, String>> entrySet = map.entrySet(); Iterator<Map.Entry<String, String>> it = entrySet.iterator(); while (it.hasNext()) { Map.Entry<String, String> next = it.next(); System.out.print(next.getKey() + "-->: " + next.getValue() + "\n"); } System.out.println("\nMap的標準輸出_2(Foreach):"); for (Map.Entry<String, String> entry : entrySet) { System.out.print(entry.getKey() + "-->: " + entry.getValue() + "\n"); } System.out.println("Map.entrySet()大小:" + map.entrySet().size()); } }
1.6. 人員配置
Java-Map集合的學習