public class HelloWorld {
public static void main(String[] args) {
// init array
String[] family = new String[] {"Member1", "Member2", "Member3", "Member4", "Member5"};
// print array
for(String name : family)
{
System.out.println(name);
}
}
}
import java.util.*;
public class HelloWorld {
public static void main(String[] args) {
// you can define the type of list you want to init - String int etc inside <yourType> eg. <String>
List<String> family = new ArrayList();
family.add("Member1");
family.add("Member2");
family.add("Member3");
family.add("Member4");
family.add("Member5");
// print array
for(String name : family)
{
System.out.println(name);
}
}
}
class Main {
public static void main(String[] args) {
// create an array
int[] age = {12, 4, 5};
// loop through the array
// using for loop
System.out.println("Using for Loop:");
for(int i = 0; i < age.length; i++) {
System.out.println(age[i]);
}
}
}
class Main {
public static void main(String args[]){
int arr[]={1,2,3,4,5};
//i starts with 0 as array index starts with 0 too
for(int i=0; i<arr.length; i++){
System.out.println(arr[i]);
}
}
}
String[] elements = {"a", "a", "a", "a"};
for (String s: elements) {
//Do your stuff here
System.out.println(s);
}
for (Class object : objects_array) {...}
public static void loopRecursive(String[] thisArray) {
if (thisArray.length <= 0) {
return;
}
System.out.println(thisArray[0]);
loopRecursive(Arrays.copyOfRange(thisArray, 1, thisArray.length));
}