T -
public class CombinationIterator<T> extends Objectimplements Iterator <List <T>>
List<String[]> input = new ArrayList<>();
input.add(new String[] {"1", "2", "3"});
input.add(new String[] {"apple", "orange"});
input.add(new String[] {"X"});
CombinationIterator<String> iter = new CombinationIterator<>(input);
while(iter.hasNext()) {
System.out.println(iter.next());
}
This code will output this list:
It helps to visualize this as a slot machine, where "1", "2", "3" are vertically stacked as one place/slot in the machine. "apple", "orange" is the next slot, and "X" is always the 3rd slot.
| Constructor and Description |
|---|
CombinationIterator(List
|
CombinationIterator(T[]... list)
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
hasNext()
|
protected void |
incrementPositions()
|
List |
next()
|
void |
remove()
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitforEachRemaining