String Array in Java

By: Dorris Viewed: 154063 times  Printer Friendly Format    


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:

C:\>javac StringCharacter.java

C:\>java StringCharacter
Lee
Freddy
Dorris
Mary
Anne
C:\>


Most Viewed Articles (in Java )

Latest Articles (in Java)

Comment on this tutorial

Subscribe to Tutorials

Related Tutorials

Archived Comments

1. I wanna to name ,subject and marks of every subjec
View Tutorial          By: raveesh yadav at 2012-10-13 19:56:47

2. Sir if i wnna to take the input from user then it
View Tutorial          By: Vivek at 2011-05-14 05:56:30

3. Thank you
View Tutorial          By: Angeline at 2011-06-28 06:27:12

4. Sir, can you give me an example of Isalnum in java
View Tutorial          By: Angeline at 2011-07-13 06:43:54

5. Why is that everyone "Sirs" you.... ???
View Tutorial          By: karthik at 2011-10-03 15:34:58

6.
View Tutorial          By: dfggfg at 2011-10-10 11:52:40

7. thank you sir, please provide me string array in d
View Tutorial          By: ravi gupta at 2012-01-17 17:04:33

8. Dear sir,
Can you provide me for a simple p

View Tutorial          By: kartikeya at 2012-12-22 10:19:41

9. Sir please can you tell me that how can i find occ
View Tutorial          By: Saad at 2013-01-20 11:14:39

10. help me in my final project about arrays
View Tutorial          By: grace at 2013-03-13 09:54:11

11. How to print lee alone for the eg above........I n
View Tutorial          By: sa at 2013-04-01 07:43:03

12. can u plz gimme a program in arrays for a student'
View Tutorial          By: hayati at 2013-12-05 14:45:27

13. Thanks for explaining character arrays and string
View Tutorial          By: Santhi at 2014-12-29 04:47:41