January 2014
Intermediate to advanced
736 pages
70h 43m
English
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" ...
Read now
Unlock full access