Previous Page

Fill array with alphabet - Java short program

Copy and Paste the following code into your favorite Java Integrated Development Environment (IDE) - compile and run.
This is an easy way to fill an array with the letters of the alphabet. This short program outputs the alphabet, also.



// Description: fill an array with the alphabet

public class fillArrayWithAlphabet
{
	public static void main(String[] args)
	{
    
		   char[] alphabet = new char[26]; // new array
         
			  
           for(char ch = 'a'; ch <= 'z'; ++ch)// fills alphabet array with the alphabet
	       {
               alphabet[ch-'a']=ch;
           } 
			  
			  System.out.print(alphabet);// output
	}
}
							
//END OF CODE