Java repeated letter check in string

后端 未结 5 518
余生分开走
余生分开走 2021-01-27 12:43

I\'m having problem figuring out how to check from users input letters that were repeated. Program needs to output repeated letter as true and if there isn\'t any then as false.

5条回答
  •  礼貌的吻别
    2021-01-27 13:30

    private static boolean check(String input) {
        Set tmp = new HashSet();
        for(char ch : input.toCharArray()) {
            if (Character.isLetter(ch) && !tmp.add(ch)) {
                return true;
            }
        }
        return false;
    }
    

提交回复
热议问题