J.5.1. ArrayList and Iterator

Figure J.2 uses an ArrayList (introduced in Section E.12) 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. J.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 Android™ How to Program, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.