Home Tutorial Java Iterator Java Previous Iterator

 
 

Share on Google+Share on Google+
Java Previous Iterator
Posted on: November 4, 2009 at 12:00 AM
Advertisement
In this section of tutorial we will learn how to use the previous method with the listIterator interface. We will create an example to display the contents of the ArrayList using previous method.

  • Java previous Iterator function is present in the listIterator Interface.
  • ListIterator is special iterator for the list.
  • previuos method allows to get the one before element of the list.
  • listIterator allows traversing in the both direction.


Java Previous Iterate Example
import java.util.ArrayList;
import java.util.ListIterator;

public class previous {

	public static void main(String[] args) {
		char alphabet = 'a';
		ArrayList list = new ArrayList();
		while (alphabet != 'z') {
			list.add(alphabet++);
		}
		
		ListIterator it = list.listIterator();
		while (it.hasNext()) {
			it.next();
		}
		while(it.hasPrevious())
		{
			System.out.print(it.previous()+"  ");
		}
	}
}

Output

y x w v u t s r q p o n m l k j i h g f e d c b a
Advertisement

Related Tags for Java Previous Iterator:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: November 4, 2009

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com