知乎专栏 |
// 将Map Key 转化为List List<String> mapKeyList = new ArrayList<String>(map.keySet()); System.out.println("mapKeyList:"+mapKeyList); // 将Map Key 转化为List List<String> mapValuesList = new ArrayList<String>(map.values()); System.out.println("mapValuesList:"+mapValuesList);
Set<Type> set = new Set<>(); Set<Type> set = new HashSet<>();
Set.toArray(IntFunction)
@Test public void testCollectionToArray(){ Set<String> names = Set.of("Fred", "Wilma", "Barney", "Betty"); String[] copy = new String[names.size()]; names.toArray(copy); System.out.println(Arrays.toString(copy)); System.out.println(Arrays.toString(names.toArray(String[]::new))); }