Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

iterator java

// Import the ArrayList class and the Iterator class
import java.util.ArrayList;
import java.util.Iterator;

public class Main {
  public static void main(String[] args) {

    // Make a collection
    ArrayList<String> cars = new ArrayList<String>();
    cars.add("Volvo");
    cars.add("BMW");
    cars.add("Ford");
    cars.add("Mazda");

    // Get the iterator
    Iterator<String> it = cars.iterator();

    // Print the elements in the list
    while(it.hasNext()){
    System.out.println(it.next());
    }
  }
Comment

how to use iterator in java

// Java code to illustrate the use of iterator
import java.io.*;
import java.util.*;
  
class Test {
    public static void main(String[] args)
    {
        ArrayList<String> list = new ArrayList<String>();
  
        list.add("A");
        list.add("B");
        list.add("C");
        list.add("D");
        list.add("E");
  
        // Iterator to traverse the list
        Iterator iterator = list.iterator();
  
        System.out.println("List elements : ");
  
        while (iterator.hasNext())
            System.out.print(iterator.next() + " ");
  
        System.out.println();
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: Horizontal RecyclerView android example 
Java :: Spring boot fix cors problem 
Java :: android studio Clearing shared preferences; 
Java :: delay a function call in java 
Java :: intent in fragment android 
Java :: java random usage 
Java :: android toast message 
Java :: Java List Sort Using sort() method 
Java :: gradle reflections 
Java :: convert array to list java 
Java :: at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1565) 
Java :: java foreach arraylist 
Java :: random java 
Java :: java convert float to int 
Java :: java stream min 
Java :: toCharArray() method java 
Java :: write input stream to file java 
Java :: ! en java 
Java :: factorial program in java 
Java :: java max int value 
Java :: remove all new line and other in string using java 
Java :: java scanner string nextline after nextint 
Java :: get timezone offset java 
Java :: java create map 
Java :: counting repeated characters in a string in java 
Java :: sum of a list using for loop in dart 
Java :: java create file in folder 
Java :: loop through an arraylist android studio 
Java :: maven paper 
Java :: java for each loop 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =