0

Coming from the Python background, in order to get all the alphabets, I am used to doing

>>> import string
>>> string.ascii_letters
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'

There are similar helper constants for lower_case and upper_case. What is the equivalent in Java. I looked into String module and could not find any.

I had to manually create a char array and it seemed superflous (or perhaps non-idiomatic) to me.

1

1 Answer 1

1

There is no such specific method in java. Specially java is designed to work with Unicode which may support all the characters used over the world. So just having english alphabet as a constant doesn't mean anything.

public static String alphabet(char letter1, char letter2) { 
    StringBuffer out = new StringBuffer();    
    for (char c = letter1; c < letter2; c++) {
        out.append(c);
    }
    return out.toString();
}

you can write the above code and call it like

String output = alphabet('a','z') + alphabet('A','Z')
Sign up to request clarification or add additional context in comments.

1 Comment

ASCII, on the other hand, does mean something.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.