Map集合中的键如何放到List集合中。我只知道将Map集合中的键字段放到Set集合中,可以直接用keySet方法.

解决方案 »

  1.   

    或者迭代Map获取key,在添加到List集合中不就行了。
      

  2.   


    public class MapKey { public static void main(String[] args) {
    Map<String,String> map=new HashMap<String,String>();
    map.put("1", "First");
    map.put("2", "Second");
    Set<String> set=map.keySet();
    List<String> list=new ArrayList<String>();
    list.addAll(set);
    for(String str:list){
    System.out.println(str);
    }
    }}
      

  3.   

    方法比较多 因为List Set都是Collection
      

  4.   

    这个就行了
    方法有多种多样
    也可以遍历Map的Key视图
    逐个添加到List中