Summary: An Array-Based Data Structure

This lesson contains the list of major points we made in this chapter.

  • A collection is an object that holds a group of other objects.
  • A bag is a collection whose entries are in no particular order. When we add an object to a bag, we cannot indicate where to place it in the bag.
  • We can remove from a bag an object having either a given value or one that is unspecified.
  • Carefully specify the methods for a proposed class before we begin to implement them, using pseudocode and CRC cards.
  • Identifying and implementing a class’s central, or core, methods before any others is a good strategy to use when we expect the class to be lengthy or complex. Use stubs for the remaining methods.
  • Test a class at each stage of its development, particularly after adding a significant method.
  • We can use a Java array to implement a bag, but other implementations are possible.
  • Adding an entry right after the last entry in an array does not disturb the position of existing entries. Likewise, deleting the last entry from an array does not disturb the position of existing entries.
  • Because a bag does not maintain its entries in a specific order, deleting an entry does not require us to move subsequent array entries to the next lower position. Instead, we can replace the entry that we want to delete with the last entry in the array and replace the last entry with null.

Get hands-on with 1200+ tech skills courses.