11:35 am - Wednesday May 24, 2017

Iterator program to iterate the elements in the List and display it using List Iterator.

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

BACK

Iterator program to iterate the elements in the List and display it using List Iterator.

Example Program


import java.util.*;

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

     // create a LinkedList
     LinkedList list = new LinkedList();

     // add some elements
     list.add("red");
     list.add("blue");
     list.add("green");
     list.add("orange");

     // print the list
     System.out.println("LinkedList:" + list);

     // set Iterator at specified index
     Iterator it = list.listIterator();

     // print list with the iterator
     while (it.hasNext()) {
        System.out.println(it.next());
     }
  }
}

 

 

Output

 

LinkedList:[red, blue, green, orange]
red
blue
green
orange

 

Description

 

The java.util.LinkedList.listIterator() method returns a list-iterator of the elements in this list.

 

Declaration

 

ListIterator<E> listiterator()

 

Parameters

 

E – the type of elements returned by this iterator

 

Return Value

 

String

 

Exception

 

NoSuchElementException – if the list iterator has no more element.

 

BACK


Filed in: Z-A All Java Codes

Comments are closed.