Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if string has all the letters of the alphabet

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 so ops. eg. Pack my box with five dozen liquor jugs.

  1. Would using a Hash be useful?
  2. Or using a bit map? or any other way?

BTW my code would be in Java.

like image 637
Vivek Avatar asked Dec 02 '22 04:12

Vivek


1 Answers

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);
like image 54
st0le Avatar answered Dec 04 '22 05:12

st0le