Java Collection Iterator
Jump to navigation
Jump to search
A Java Collection Iterator is a Collection Iterator expressed as a Java statement.
References
2011
- Example
import java.math.BigDecimal; import java.util.List; import java.util.Iterator; import java.util.ArrayList; public class TestIteration { public static void main(String[] args) { List<BigDecimal> vals = new ArrayList<BigDecimal>(); vals.add(new BigDecimal(2.4)); vals.add(0, new BigDecimal(3.7)); // insert at the head vals.add(0, new BigDecimal(7.0)); Iterator<BigDecimal> iter = vals.iterator(); while (iter.hasNext()) {System.out.println(iter.next()) ;} performTask(iter) ; } static void performTask (Iterator<BigDecimal> iter) { while (iter.hasNext()) { System.out.println(iter.next()) ; } } }