Home Tutorial Java Iterator Iterator Java Reset


Share on Google+Share on Google+
Iterator Java Reset
Posted on: November 4, 2009 at 12:00 AM
In this section of tutorial we will learn how to reset the ArrayList contents.We will create an example to display the contents of the ArrayList after resetting it.
  • iterator interface doesn't have any reset method.
  • In the listIterator the previous method can be used to rsest the list.

Example of Java Reset Iterator

import java.util.ArrayList;
import java.util.Iterator;
import java.util.ListIterator;

public class reset {

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


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

Related Tags for Iterator Java Reset:

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