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