Programming Tutorials

String Array in Java

By: Dorris in Java Tutorials on 2010-12-27  

This tutorial demonstrates using string array in Java. Here, you will see how to declare a string array and the syntax for using in the program.

Following code of the program declares a string array and stores some strings of first names like "Lee", "Freddy", "Dorris", "Mary", and "Anne" to it. And in the main method these string are displayed one by one by retrieving from the specified string array named firstnames. In this program all the string values are stored in the firstnames string array at the declaration time.

Sample Code:

class StringCharacter 
{
  static String[] firstnames={"Lee", "Freddy", "Dorris", "Mary","Anne"};
  public static void main(String args[]){
    for(int i=0;i<5;i++){
    System.out.println(firstnames[i]);
    }
  }
}

Output of program:

Lee
Freddy
Dorris
Mary
Anne





Add Comment

* Required information
1000

Comments

No comments yet. Be the first!

Most Viewed Articles (in Java )

Latest Articles (in Java)