Over 10 Million Study Resources Now at Your Fingertips

Download as :
Rating : ⭐⭐⭐⭐⭐
Price : $10.99
Pages: 2

Let examine the myiterator class that follows

Looping Constructs

Implementing the Iterator interface
As mentioned earlier, any class that implements the Iterable interface can be used with the for-each statement. To illustrate this we will create two classes:

import java.util.Iterator;

public class MyIterator implements Iterator<Integer> { private int value;
private final int size;

[ 164 ]

Chapter 5

public Iterator<Integer> iterator() {
return iterator;

We can test these classes with the following code sequence:

The use of the Iterator methods for iterating through a

statement provides a much more convenient and simple technique.

[ 165 ]

How It Works
Login account
Login Your Account
Add to cart
Add to Cart
Make payment
Document download
Download File
PageId: ELIFEF2448
Uploaded by :
Page 1 Preview
let examine the myiterator class that follows
Sell Your Old Documents & Earn Wallet Balance