dimanche 23 mai 2021

Check if there is a duplicate letter within a string regardless of lowercase or uppercase

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

I am quite new to programming and i found a way to find a duplicate letter within a string but how would i be able to return true if the duplicate letter was a capital or non-capital for example "Aa".

Aucun commentaire:

Enregistrer un commentaire