Assign ASCII character AZ in the list

I need to get characters from AZ to ASCII and assign it to a string array or list and loop through it. Any idea on how to extract ASCII characters and assign it to an array other than String[] Asci= {"A","B","C","D","E","F".....etc)

.

+3


source to share


5 answers


List <String> ascii = new ArrayList <String> (26);

for (char c = 'A'; c <= 'Z', c++)
    ascii.add (String.valueOf (c));

      



+4


source


In Unicode (used with Java strings), the characters A through Z produce a contiguous sequence, so using a loop is possible. "A", however, is not the first character in Unicode. This can be done in a general way, without assuming character codes, and simply assuming that there is a sequence from A to Z with no other codes in between.



char values[] = new char['Z'-'A'];

int i = 0;
for (char c='A'; c<='Z'; c++)
  values[i++] = c;

      

+1


source


try something like this:

It will keep the first 256 ascii characters

for (int i=0; i<256; i++){
  char temp = i;
  values[i] = temp;
}

      

0


source


public static void main(String[] args)
{
    String alpha[] = new String[26];
    for (char c = 65; c <= 90; c++)
    {
        alpha[c - 65] = String.valueOf(c);
    }

    for (String s : alpha)
    {
        System.out.println(s);
    }
}

      

0


source


see this .....

public class Alphabet {
public Alphabet() {
for ( int i = 65; i < 91; i ++ ) {
System.out.println("Upper Case\n"+(char)i + " " + (char)(i+32));
}
}
public static void main(String [] args) {
new Alphabet();
}
}

      

0


source







All Articles