Collections Homework


  1. Show the fields of the given Collection after the following sequence of Collection operations are executed. Show any values returned by the operations
  2.    ArrayCollection<String> strcoll = new ArrayCollection<String>();
       strcoll.add("red");
       strcoll.add("blue");
       strcoll.add("black");
       strcoll.add("orange");
       boolean ok = strcoll.contains("black");
       String str = strcoll.get("white");
       strcoll.remove("black");
       strcoll.add("green");
    
  3. Show the fields of the given Collection after the following sequence of Collection operations are executed. Show any values returned by the operations
  4.    LinkedCollection<String> strcoll = new LinkedCollection<String>();
       strcoll.add("red");
       strcoll.add("blue");
       strcoll.add("black");
       strcoll.add("orange");
       boolean ok = strcoll.contains("black");
       String str = strcoll.get("white");
       strcoll.remove("black");
       strcoll.add("green");
    
  5. Write a method boolean replace(T old, T new) for the ArrayCollection class. The method should replace every occurrence of old with new. If old is not found in the Collection, the method should return false; otherwise it should return true.
  6. Write a method boolean replace(T old, T new) for the LinkedCollection class. The method should replace every occurrence of old with new. If old is not found in the Collection, the method should return false; otherwise it should return true.
  7. Write code to do the following:


Email Me | Office Hours | My Home Page | Department Home | MCC Home Page

© Copyright Emmi Schatz 2017