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 :: java timeout exception 
Java :: index 1 out of bound for length 1 java 
Java :: how to print each element of an arraylist on a new line in java 
Java :: java indexof nth occurrence 
Java :: list of java 
Java :: the import junit cannot be resolved maven 
Java :: set web image to imageview android java 
Java :: java integer object to char 
Java :: JAVA Multi-line Comment 
Java :: stringbuilder in java 
Java :: Java Scanner nextInt() 
Java :: next line java does not take input 
Java :: what is ioexception in java 
Java :: terminate function calling in java 
Java :: how to create a new imageview in android java 
Java :: convert string array to string 
Java :: find minimum element in a sorted and rotated array 
Java :: void * to int 
Java :: java println format 
Java :: meter to cm 
Java :: spring security controlleradvice 
Java :: how to use a while statement with char in java 
Java :: How do you make bedrock full screen in Minecraft? 
Java :: Plugin execution not covered by lifecycle configuration: org.apache.maven.plugins:maven-compiler-plugin:3.10.1:compile (execution: default-compile, phase: compile) 
Java :: java transformar string a url 
Java :: get sha1 key from keystore 
Java :: one space diagonally in java 
Java :: java stream list order lambda 
Java :: hgjhghj 
Java :: SmallChange 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =