Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Java Beginners String Array In Java

 
 

Share on Google+Share on Google+

String Array In Java

Advertisement
In this section, you will learn how to use string array in Java.

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.

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: June 5, 2007

Related Tutorials

Discuss: String Array In Java   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:12
radhakrishnan
November 11, 2011
codings

store and retrive values in java without using database.how to create
roshni sanhaliya
November 30, 2011
java proamming

thank u
Gianne
January 10, 2012
datastructure lab

i can't understand!
Gianne
January 10, 2012
datastructure lab

i can't understand
Ashok Naik
February 17, 2012
Strings

1)how to count number of strings repeated in a string array? 2)i want to display the output like Naik Ashok instead of Ashok Naik ...what is the logic of this program?
Ravi
March 11, 2012
Switch String in Java

How to use string in switch statement in Java.
Ravi
March 11, 2012
Switch Statement using String

How to use Switch statement in Java using String. switch(String s){...}. This is the not working. Please could I get exactly how should be written. Any one please help me.
roy charman
December 9, 2012
string arrays

For one of my college assignments I have to enter a string (ones that's already been declared) (the name of a song artist) then for I need the program to out put the string location (the chart rating of the aritist) how can I do this? I'm quite stuck
Bhim prasad sharma
October 3, 2013
mj.Geoff

package Practise; import java.util.*; import java.util.Scanner; public class testShape { static Scanner console=new Scanner(System.in); public static void main(String[]args) { Circle c=new Circle(); Square s=new Square(); Rectangle r=new Rectangle(); Triangle t=new Triangle(); int input=0; double radius=0; System.out.println("This program will compute the area of Circle, Triangle, Square and Rectangle.\n"); System.out.println("You are required to enter input and kindly follow the direction. \n "); System.out.println("Just choose below what area do you want to know.\n "); System.out.println("circle, triangle, rectangle, square: \n"); String choice=console.next(); /*System.out.println("\nEnter for a loop number: "); input=console.nextInt(); String[] choice=new String[input]; for(int i=0; i<choice.length;i++){ System.out.println("circle, triangle, rectangle, square \n input: "); choice[i]=console.next(); */ if (choice.equals("circle")){ System.out.println("Please Enter the radius, area, diameter"); String givenType=console.next(); c.setGiven(givenType); c.condition(givenType, radius, radius, radius); } else if(choice.equals("triangle")) { t.computeTriangle(radius, radius); } else if(choice.equals("rectangle")){ r.computeRectangle(radius, radius); } else if(choice.equals("square")){ System.out.println("This program will compute for the Area of a squre"); s.computeSquare(radius); } else System.out.println("your input is not in the choices given!"); } }
DMCA.com