Right now I'm doing
for (char c = 'a'; c <= 'z'; c++) { alphabet[c - 'a'] = c; }
but is there a better way to do it? Similar to Scala's 'a' to 'z'
void createMine(int i); string alphabet[26] = { "a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z" };
char[] arr = { 'p', 'q', 'r', 's' }; The method valueOf() will convert the entire array into a string. String str = String. valueOf(arr);
I think that this ends up a little cleaner, you don't have to deal with the subtraction and indexing:
char[] alphabet = "abcdefghijklmnopqrstuvwxyz".toCharArray();
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