-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayExample.java
More file actions
23 lines (19 loc) · 902 Bytes
/
ArrayExample.java
File metadata and controls
23 lines (19 loc) · 902 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package string.stringclass;
import java.lang.String;
public class ArrayExample {
public static void main(String[] args) {
// declaration of array...
// String [] name; // this is best way for declare a array...
// String name[]; --> valid way...
// String [] name = new String[5]; --> declare and memory allocate same time...
// String [] name = {"ravi", "bittu", "rohan", "mercy", "lucky"}; --> declare and initialization same time...
// String [5] name; --> invalid way because not allocate memory in such way...
// method of array
// name = new String[5]; // memory allocation
// System.out.println("Memory allocated for an array: " + name);
String [] names = {"ravi", "bittu", "rohan", "mercy", "lucky"};
for (String name : names){
System.out.println(name);
}
}
}