Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

iterate Through ArrayList Java

import java.util.ArrayList;

class Main {
  public static void main(String[] args) {
    ArrayList<String> animals = new ArrayList<>();

    // add elements in the arraylist
    animals.add("Peacock");
    animals.add("Markhor");
    animals.add("Cow");
    System.out.println("ArrayList: " + animals +"
");

// iterate using for-each loop
    System.out.println("Accessing individual elements:  
");
    for (String language : animals) {
      System.out.print(language);
      System.out.print("
");
    }
  }
}
Source by softhunt.net #
 
PREVIOUS NEXT
Tagged: #iterate #Through #ArrayList #Java
ADD COMMENT
Topic
Name
2+3 =