Using collections before Java 9

Here is an example of how we would create our own collections prior to Java 9. This first class defines the structure for PlanetCollection. It has the following components:

  • A single instance variable
  • A one argument constructor
  • Mutator/setter method
  • Accessor/getter method
  • Method to print the object

Here is the code implementing the preceding listed constructor and methods:

    public class PlanetCollection     {      // Instance Variable      private String planetName;      // constructor      public PlanetCollection(String name)      {        setPlanetName(name);      }      // mutator      public void setPlanetName(String name)      {        this.planetName = name;      }      // accessor      public String getPlanetName()      {        return this.planetName;      }      public void print()      {        System.out ...

Get Java 9: Building Robust Modular Applications 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.