array

How to declared character array with full description

Page 1 of 1

2 Replies - 591 Views - Last Post: 30 December 2009 - 08:39 AM Rate Topic: -----

#1 manjusha_27_joshi@yahoo.co.in  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 29-December 09

array

Post icon  Posted 30 December 2009 - 12:00 AM

I don't know how to declared string array in java that's why it is not implemented in programming in java.


View Postmanjusha_27_joshi@yahoo.co.in, on 29 Dec, 2009 - 10:58 PM, said:

I don't know how to declared string array in java that's why it is not implemented in programming in java.


Is This A Good Question/Topic? 0
  • +

Replies To: array

#2 no2pencil  Icon User is online

  • Admiral Fancy Pants
  • member icon

Reputation: 5394
  • View blog
  • Posts: 27,389
  • Joined: 10-May 07

Re: array

Posted 30 December 2009 - 12:02 AM

Taken from : Sun.com

Posted Image

The following program, ArrayDemo, creates an array of integers, puts some values in it, and prints each value to standard output.
	class ArrayDemo {
		 public static void main(String[] args) {
			  int[] anArray;			  // declares an array of integers

			  anArray = new int[10];	  // allocates memory for 10 integers
				
			  anArray[0] = 100; // initialize first element
			  anArray[1] = 200; // initialize second element
			  anArray[2] = 300; // etc.
			  anArray[3] = 400;
			  anArray[4] = 500;
			  anArray[5] = 600;
			  anArray[6] = 700;
			  anArray[7] = 800;
			  anArray[8] = 900;
			  anArray[9] = 1000;

			  System.out.println("Element at index 0: " + anArray[0]);
			  System.out.println("Element at index 1: " + anArray[1]);
			  System.out.println("Element at index 2: " + anArray[2]);
			  System.out.println("Element at index 3: " + anArray[3]);
			  System.out.println("Element at index 4: " + anArray[4]);
			  System.out.println("Element at index 5: " + anArray[5]);
			  System.out.println("Element at index 6: " + anArray[6]);
			  System.out.println("Element at index 7: " + anArray[7]);
			  System.out.println("Element at index 8: " + anArray[8]);
			  System.out.println("Element at index 9: " + anArray[9]);
		 }
	} 



The output from this program is:

Quote

Element at index 0: 100
Element at index 1: 200
Element at index 2: 300
Element at index 3: 400
Element at index 4: 500
Element at index 5: 600
Element at index 6: 700
Element at index 7: 800
Element at index 8: 900
Element at index 9: 1000

Was This Post Helpful? 0
  • +
  • -

#3 Luckless  Icon User is offline

  • </luck>
  • member icon

Reputation: 293
  • View blog
  • Posts: 1,146
  • Joined: 31-August 09

Re: array

Posted 30 December 2009 - 08:39 AM

For a String array, you would just follw the above instructions but set up the data type as a String instead of an int like this:


String[] arrayName = new String[someNumber];



after that, you can put Strings directly into array positions like it is shown in that nifty little demo from Sun. Best of luck! :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1