Run Application
Create new package named demo. In this package, create new java class named Main.java as below:
package demo;
public class Main {
public static void main(String[] args) {
var names = new String[4];
names[0] = "name 1";
names[1] = "name 2";
names[2] = "name 3";
names[3] = "name 4";
System.out.println("Name List 1");
for (var name : names) {
System.out.println(name);
}
System.out.println("Name List 2");
for (var i = 0; i < names.length; i++) {
System.out.println(names[i]);
}
}
}
Output
Name List 1
name 1
name 2
name 3
name 4
Name List 2
name 1
name 2
name 3
name 4