Skip to main content

Declaring String Array

In java String is a Class not a Variable.
Let’s Understand how to declare String Array

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package com.spy.javaforlearn;
 
public class Foreach 
{
 
	public static void main(String[] args) 
	{
 
      	String[] name=new String[3];
 
	    name[0]="Bhavesh";
	    name[1]="Abhilash";
	    name[2]="Vivek";
 
	    //accessing element
 
	    System.out.println("accessing Array element.......");
 
	    for (String s : name) 
	    {
 
	    	System.out.println(s);
		}
 
	}
}

Output:

1
2
3
4
accessing Array element.......
Bhavesh
Abhilash
Vivek