Collections Homework
- Show the fields of the given Collection after the following
sequence of Collection operations are executed. Show any values
returned by the operations
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");
- Show the fields of the given Collection after the following
sequence of Collection operations are executed. Show any values
returned by the operations
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");
- 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.
- 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.
- Write code to do the following:
- Create an ArrayCollection of Strings.
- Write a loop that will prompt the user for Strings and
add each String to the Collection.
- Prompt the user for an old String and a new String, then
replace the old String in the Collection with the new
String.
- Print a message stating whether the replacement was
successful.
- Print the number of elements in the Collection.
Email Me |
Office Hours |
My Home Page |
Department Home |
MCC Home Page
© Copyright Emmi Schatz 2017