String Array in Java

By: Dorris  

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++){

Output of program:


C:\>java StringCharacter

Archived Comments

1. Thanks for explaining character arrays and string arrays very well here. You can also get more insig
View Tutorial          By: Santhi at 2014-12-29 04:47:41

2. can u plz gimme a program in arrays for a student's marksheet.... avg mks, total, who stands first,
View Tutorial          By: hayati at 2013-12-05 14:45:27

3. How to print lee alone for the eg above........I need to print the name LEE to get a par
View Tutorial          By: sa at 2013-04-01 07:43:03

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

5. Sir please can you tell me that how can i find occurrence of second "A" the string "S
View Tutorial          By: Saad at 2013-01-20 11:14:39

6. Dear sir,
Can you provide me for a simple program in which three strings are accepted-a main

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

7. I wanna to name ,subject and marks of every subject with for loop. thank sir.
View Tutorial          By: raveesh yadav at 2012-10-13 19:56:47

8. thank you sir, please provide me string array in detail, supose i want print customer detail as his
View Tutorial          By: ravi gupta at 2012-01-17 17:04:33

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

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

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

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

13. Sir if i wnna to take the input from user then it shows nullpointerexception. hw can we take input f
View Tutorial          By: Vivek at 2011-05-14 05:56:30

Most Viewed Articles (in Java )

Latest Articles (in Java)

Comment on this tutorial