String Array In Java

In this section, you will learn how to use string array
in Java. Here, you will see how to declare a string array and the syntax for
using in the program. This section provides you a simple java program which
illustrates about the string array in very efficient manner.
Program Description:
Following code of the program declares a string array
and store some strings like "chandan", "tapan", "Amar", "santosh", and "deepak"
to it. And in the main method these string are displayed one by one by
retrieving from the specified string array named roseindia. In this program all
the string values are stored in the roseindia string array at the declaration
time.
Here is the code of this program:
class StringCharacter
{
static String[] roseindia={"chanan","tapan","Amar","santosh","deepak"};
public static void main(String args[]){
for(int i=0;i<5;i++){
System.out.println(roseindia[i]);
}
}
}
|
Output of program:
C:\>javac StringCharacter.java
C:\>java StringCharacter
chanan
tapan
Amar
santosh
deepak
C:\> |
Download this Example.

|