Difference between revisions of "Iterable Immutable List Assignment"
Jump to navigation
Jump to search
Line 20: | Line 20: | ||
#[https://docs.oracle.com/javase/8/docs/api/java/util/Iterator.html#next-- T next()] | #[https://docs.oracle.com/javase/8/docs/api/java/util/Iterator.html#next-- T next()] | ||
− | = | + | =Examples= |
+ | ==Using Iterable== | ||
+ | <youtube>A-rTJTHq5B4</youtube> | ||
+ | ==Implementing Iterable== | ||
==DoubleRange== | ==DoubleRange== | ||
<youtube>Dww-_5EiwA8</youtube> | <youtube>Dww-_5EiwA8</youtube> | ||
+ | ==ArrayIterable== | ||
+ | <youtube>PfKnQzbztfo</youtube> | ||
=Example= | =Example= |
Revision as of 19:00, 24 April 2020
Contents
Studio To Revisit
In this studio we will complete the DefaultImmutableList
implementation from the ImmutableList studio.
ImmutableList
The ImmutableList interface extends Iterable which has one method: iterator().
public interface ImmutableList<E> extends Iterable<E> { E head(); ImmutableList<E> tail(); boolean isEmpty(); }
Iterable
interface java.lang.Iterable<T>
Iterator
interface java.util.Iterator<T>
Examples
Using Iterable
Implementing Iterable
DoubleRange
ArrayIterable
Example
class: | Mary Berry.java | |
package: | immutable.list.example | |
source folder: | src/main/java |
The code:
ImmutableList<Integer> numbers = Lists.brackets(4, 66, 99); for (Integer i : numbers) { System.out.println(i); }
produces:
4 66 99
Test
class: | IterableAssignmentTestSuite.java | |
package: | immutable.list.assignment | |
source folder: | src/test/java |