COLLEGE OF COMPUTER STUDEIS
INFORMATION TECHNOLOGY DEPARTMENT
CCS0023L
(Object Oriented Programming)
EXERCISE
9
Declaring and Using Different Java Collections
<STUDENT NAME>
<SECTION>
<DATE>
I. OBJECTIVES:
At the end of the experiment, students must be able to:
Cognitive
a) Learn the behavior of the Collections Interface
b) Learn the behavior of the Set Interface
c) Learn the behavior of the List Interface
d) Learn the behavior of the Map Interface
Psychomotor:
a) construct a program using set, list and map interface
b) compile and debug the error of the program
Affective
a) appreciate the concept behind this experiment
II. BACKGROUND INFORMATION
A Collection (also known as container) is an object that contains a group of objects
treated as a single unit.
A List cares about the index, a Set doesn’t allow duplicates and a Map cares about the
unique identifiers.
III. EXPERIMENTAL PROCEDURE:
1. Create a program that will prompt the user to choose from the menu:
A. Vector
B. TreeSet
C. Hashtable
D. Exit
If the user selects A, ask the user to enter five pet names. Using vector, sort and display
the names in alphabetical order. Then prompt the menu.
If the user selects B, do as if the user selects A but this time apply TreeSet. Output is the same.
The menu will appear afterwards.
If the user selects C, input the following:
PetType:
PetName:
PetColor:
PetAge:
PetSize:
After inputting, together with the above pet info, display the answer using Hashtable. Then
prompt the menu.
V. QUESTION AND ANSWER:
1. The following program is supposed to print the string "Blue". Instead, it throws
an error. Why?
import java.util.*;
public class SortMe {
public static void main(String args[]) {
SortedSet<StringBuffer> s
= new TreeSet<StringBuffer>();
s.add(new StringBuffer("Red"));
s.add(new StringBuffer("White"));
s.add(new StringBuffer("Blue"));
System.out.println(s.first());
}
}
______________________________________________________________________________
______________________________________________________________________________
_____________________________________________________________________________
Topic Collections
Lab Activity No 9
Lab Activity Declaring and Using Different
Java Collections
CLO 2
Program execution (20)
Correct output (20)
Design of output (10)
Design of logic (20)
Standards (20)
Delivery (10)
TOTAL