Question: help with this code, output supoose to be ( 1 , 2 , 2 , 3 , false ) and ( 1 0 0 ,
help with this code, output supoose to be false and null,null,false
import java.util.Iterator;
import java.util.ArrayList;
import java.util.List;
public class MyIterator implements Iterator
private List list;
private int index;
public MyIteratorIterator iterator
this.list new ArrayList;
whileiteratorhasNext
this.list.additeratornext;
this.index ;
public Integer lookAhead
ifindex list.size
return list.getindex;
return null;
@Override
public boolean hasNext
return index list.size;
@Override
public Integer next
ifhasNext
return null;
Integer element list.getindex;
index;
return element;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class HW
public static void mainString args
List ints new ArrayListArraysasList;
MyIterator iter new MyIteratorintsiterator;
System.out.printlniternext;
System.out.printlniterlookAhead;
System.out.printlniternext;
System.out.printlniternext;
System.out.printlniterhasNext; false
ListArraysasListp
MyIterator iter new MyIteratorintsiterator;
System.out.printlniternext;
System.out.printlniterlookAhead; null
System.out.printlniternext; null
System.out.printlniterhasNext; false
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
