标签:image iterator ref 来讲 info pack 实例化 strong 技术分享
对于集合来讲,就是把kye-value的数据保存在了Map.Entry的实例之后,再在Map集合中插入了一个Map.Entry的实例化对象
Map.Entry一般用于输出集合
方案一:
方案二:
package com.ftl; import java.util.Collection; import java.util.Iterator; import java.util.Map; import java.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()); } }
标签:image iterator ref 来讲 info pack 实例化 strong 技术分享
原文地址:https://www.cnblogs.com/ftl1012/p/9216647.html