How to generate an array of the alphabet letters in Java

4 Answers

0 votes
package javaapplication1;

import java.util.Arrays;

public class JavaApplication1 {
 
    public static void main(String[] args) {
        
        char[] alphabet = new char[26];
        
        for (char ch = 'a'; ch <= 'z'; ch++)
            alphabet[ch - 'a'] = ch;
        
        System.out.println(Arrays.toString(alphabet));
    }
}
   
/*
run:
  
[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]
   
*/

 



answered Mar 20, 2017 by avibootz
0 votes
package javaapplication1;

import java.util.Arrays;

public class JavaApplication1 {
 
    public static void main(String[] args) {
        
        char[] alphabet = "abcdefghijklmnopqrstuvwxyz".toCharArray();

        System.out.println(Arrays.toString(alphabet));
    }
}
   
/*
run:
  
[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]
   
*/

 



answered Mar 20, 2017 by avibootz
0 votes
package javaapplication1;

import java.util.Arrays;

public class JavaApplication1 {
 
    public static void main(String[] args) {
        
        char[] alphabet = {'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'};

        System.out.println(Arrays.toString(alphabet));
    }
}
   
/*
run:
  
[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]
   
*/

 



answered Mar 20, 2017 by avibootz
0 votes
package javaapplication1;

import java.util.Arrays;

public class JavaApplication1 {
 
    public static void main(String[] args) {
        
        char[] alphabet = new char[26];
        
        int j = 0;
        for(int i = 97; i < (97 + 26); i++)
            alphabet[j++] = (char)i;
            
        System.out.println(Arrays.toString(alphabet));
    }
}
   
/*
run:
  
[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]
   
*/

 



answered Mar 20, 2017 by avibootz

Related questions

3 answers 188 views
2 answers 173 views
2 answers 183 views
2 answers 172 views
3 answers 329 views
1 answer 191 views
4 answers 380 views
...