map集合转set集合
import java.util.*; //Map集合的迭代器输出,先将Map集合变为Set集合,再使用Iterator迭代器 public class Java_collection { public static void main(String[] args) { Map<Integer, String> map = new HashMap<>(); map.put(1, "张三"); map.put(2, "李四"); map.put(3, "王五"); //输出Map集合 //1.Map -> Set Set<Map.Entry<Integer, String>> set = map.entrySet(); //2.取得Set接口迭代器 Iterator<Map.Entry<Integer, String>> iterator = set.iterator(); //3.迭代输出 while (iterator.hasNext()) { Map.Entry<Integer, String> entry = iterator.next(); System.out.println(entry.getKey() + "=" + entry.getValue()); } List<Integer> list = new ArrayList<>(); Collections.addAll(list,1,3,5,4,7,6,9); } }