I have a situation where I need to find a letter's index in the alphabet. In Python I could use string.ascii_lowercase
or string.ascii_uppercase
. Is there something similar in Java?
Obviously I could do:
private static char[] alphabet = "abcdefghijklmnopqrstuvwxyz".toCharArray();
But after so much Python, it makes me wonder if this is built in somewhere.
You can get the index like this:
char lowercaseLetter = ...
int index = lowercaseLetter - 'a';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With