OrderedStringListType - import java.util.Arrays import java.util.HashSet import java.util.Iterator import java.util.Set Holds a list of String objects

OrderedStringListType - import java.util.Arrays import...

This preview shows page 1 - 2 out of 6 pages.

import java.util.Arrays; import java.util.HashSet; import java.util.Iterator; import java.util.Set; /** * Holds a list of String objects always sorted * in ascending order. * * @author Zachary Latta */ public class OrderedStringListType implements Iterable<String> { private final int DEFAULT_CAPACITY = 10; private final int RESIZE_FACTOR = 2; private String[] list; private int elements; /** * Creates an empty list of the default capacity. */ public OrderedStringListType() { list = new String[DEFAULT_CAPACITY]; elements = 0; } /** * This constructor creates an empty list of the specified capacity. * * @param capacity The initial capacity. * @throws IllegalArgumentException if the specified capacity is less than one. */ public OrderedStringListType(int capacity) { if(capacity < 1) { throw new IllegalArgumentException(); } list = new String[capacity]; elements = 0; } /** * Adds a string to the list. * * @param str The string to add. */ public void add(String str) { // Check if there's anything in the list before checking against it.
Image of page 1
Image of page 2

You've reached the end of your free preview.

Want to read all 6 pages?

  • Spring '14
  • Zachary Latta

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture