16.6.1 ArrayList and Iterator

Figure 16.2 uses an ArrayList (introduced in Section 7.16) to demonstrate several capabilities of interface Collection. The program places two Color arrays in ArrayLists and uses an Iterator to remove elements in the second ArrayList collection from the first.

 1   // Fig. 16.2: CollectionTest.java 2   // Collection interface demonstrated via an ArrayList object. 3   import java.util.List; 4   import java.util.ArrayList; 5   import java.util.Collection; 6   import java.util.Iterator; 7  8   public class CollectionTest 9   {10      public static void main(String[] args)11      {12         // add elements in colors array to list13         String[] colors = {"MAGENTA", "RED", "WHITE" ...

Get Java™ How To Program (Early Objects), Tenth Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.