Over 10 Million Study Resources Now at Your Fingertips


Download as :
Rating : ⭐⭐⭐⭐⭐
Price : $10.99
Language:EN
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

@Override
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
Payment
Make payment
Document download
Download File
PageId: ELIFEF2448
img
Uploaded by :
Pp5kjw1B
Page 1 Preview
let examine the myiterator class that follows
Sell Your Old Documents & Earn Wallet Balance