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

8.6. Set

8.6.1. Set 初始化

			
    private List<Fragment> fragmentList = new ArrayList<>() {{
        add(new ShareFullscreenFragment());
        add(new StoryFullscreenFragment());
        add(new MessageFullscreenFragment());
        add(new MeFullscreenFragment());
    }};
			
			

8.6.2. 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.6.3. Set.of()

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

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