Check if string has all the letters of the alphabet

前端 未结 15 1359
终归单人心
终归单人心 2020-12-19 17:51

What would be the best logic to check all the letters in a given string.

If all the 26 letters are available in the provided string, I want to check that and perform

15条回答
  •  抹茶落季
    2020-12-19 18:13

    Using a BitMap, I'm assuming you meant case insenstive.

    Update: Solution by Thomas is more efficient, than the following. :) Use that one.

        //
        String test  = "abcdefeghjiklmnopqrstuvwxyz";
    
        BitSet alpha = new BitSet(26);
        for(char ch : test.toUpperCase().toCharArray())
            if(Character.isLetter(ch))
                alpha.set(ch - 65);
    
        System.out.println(alpha.cardinality() == 26);
    

提交回复
热议问题