Map的value转化为其它类型

map的values()
Collection v = map.values(); 转化为数组或者List集合

//转化为List:
List<String> l=new ArrayList<String>(map.values());
for(String s:l){
   System.out.print(s);
}

转化为数组

//1.直接为Object[]数组
Object[] array = map.values().toArray();
for(Object s:array){
   System.out.print(s);
}

//2.转化为value泛型的数组(此处为String[])
String[] strings = map.values().toArray(new String[map.size()]);
for(String s:strings){
   System.out.print(s);
}
posted @ 2022-05-18 09:27  寒冷的雨呢  阅读(1381)  评论(0编辑  收藏  举报