Home  Listings  By Name  By Subject  Email  www.tomswan.com  Help 

Java 2 Just Click! Solutions

Chapter 14 Listings

© 2001 by Tom Swan. All rights reserved. Updated: 6/4/01 12:20:54 PM

Return to Listings page
Switch to Solutions by name page
Switch to Solutions by subject page


Listing 14-1 Collection.txt Page 270

Return to top
001: // Collection interface methods
002: int size();
003: boolean isEmpty();
004: boolean contains(Object o);
005: Iterator iterator();
006: Object[] toArray();
007: Object[] toArray(Object a[]);
008: boolean add(Object o);
009: boolean remove(Object o);
010: boolean containsAll(Collection c);
011: boolean addAll(Collection c);
012: boolean removeAll(Collection c);
013: boolean retainAll(Collection c);
014: void clear();
015: boolean equals(Object o);
016: int hashCode();
Return to top

Listing 14-2 ContainerDemo/ContainerDemo.java Page 272

Return to top
001: import java.util.ArrayList;
002: 
003: class ContainerDemo {
004:  public static void main(String args[]) {
005:   ArrayList myList = new ArrayList(25);
006:   myList.add(new String("One"));
007:   myList.add(new String("Two"));
008:   myList.add("Buckle");
009:   String s = "My shoe";
010:   myList.add(s);
011:   System.out.println("There are " + 
012:    myList.size() + " strings in myList");
013:   for (int i = 0; i < myList.size(); i++)
014:    System.out.println(myList.get(i));
015:  }
016: }
Return to top