Advertisement
Methods | Description |
---|---|
void add(E obj) | Inserts an object in the front of the list. |
boolean hasNext() | Returns true if there is a next element in a list, otherwise, returns false. |
E next() | Returns the next element in a list. |
boolean hasPrevious() | Returns true if there is a previous element in a list, otherwise, returns false. |
E previous() | Returns the previous element in a list. |
void remove() | Removes the current element from the list. |
void set(E obj) | Sets the value of the current element to value of obj. |
Advertisement
import java.util.*;
class ListIteratorDemo
{
public static void main(String... ar)
{
ArrayList arr= new ArrayList();
arr.add("F");
arr.add("O");
arr.add("R");
arr.add("W");
arr.add("A");
arr.add("R");
arr.add("D");
ListIterator itr = arr.listIterator();
System.out.println("Iteraring the list in forward direction");
System.out.print("Contents of ArrayList are : ");
while(itr.hasNext())
{
System.out.print(itr.next() + " " );
}
System.out.println();
System.out.println("Iteraring the list in backward direction");
System.out.print("Contents of ArrayList are : ");
while(itr.hasPrevious())
{
System.out.print(itr.previous() + " " );
}
System.out.println();
System.out.println("Size of arraylist = "+ arr.size());
}
}
Iteraring the list in forward direction
Contents of ArrayList are : F O R W A R D
Iteraring the list in backward direction
Contents of ArrayList are : D R A W R O F
Size of arraylist = 6
Advertisement
Advertisement
Please check our latest addition
C#, PYTHON and DJANGO
Advertisement