Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[20210204] Java Map에서 Value가 2이상인 key들에 대해 List로 return #31

Open
JuHyun419 opened this issue Feb 4, 2021 · 0 comments
Labels

Comments

@JuHyun419
Copy link
Owner

Map<String, Integer> map = new HashMap<>(); 에서 value가 2 이상인 데이터(중복)에 대한 key를 List로 리턴

        Map<String, Integer> map = new HashMap<>();
        map.put("010", 2);
        map.put("016", 1);
        map.put("011", 3);

        List<String> keys = map.entrySet()
            .stream()
            .filter(e -> e.getValue() > 1)
            .map(Map.Entry::getKey)
            .collect(Collectors.toList());
        
        for (String s : keys) {
            System.out.println(s + ", " + map.get(s));
        }

// 011, 3
// 010, 2
@JuHyun419 JuHyun419 added the Java label Feb 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant