Home | 简体中文 | 繁体中文 | 杂文 | Github | 知乎专栏 | Facebook | Linkedin | Youtube | 打赏(Donations) | About
知乎专栏

8.5. Set 转为 List

			
		// 将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<>();		
		
		

8.5.1. Set.of()

		
Set<Integer> ints = Set.of(1, 2, 3);		
		
			

8.5.2. Set to Array

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)));
    }