Java Reference
In-Depth Information
Review Questions
1. Suppose you have a collection of products for sale in a database and you need to display
those products on a web page. The Java code on the server needs to be able to sort the
products by price and category. Which of the following collections classes in the java.util
package best suit your needs for this scenario?
A. HashSet
B. HashMap
C. PriorityQueue
D. Arrays
E. ArrayList
2. Suppose you need to work with a collection of elements that need to be sorted in their natu-
ral ordering, iterated in descending order, and each element has a unique string associated
with its value. Which of the following collections classes in the java.util package best
suit your needs for this scenario?
A. HashMap
B. TreeMap
C. HashSet
D. Vector
E. ArrayList
3. What is the result of the following statements?
6. List list = new ArrayList();
7. list.add(“one”);
8. list.add(“two”);
9. list.add(7);
10. for(String s : list) {
11. System.out.print(s);
12. }
A. onetwo
B. onetwo7
C. onetwo followed by an exception
D. Compiler error on line 9
E. Compiler error on line 10
4. What is the result of the following statements?
6. List<String> list = new ArrayList<String>();
7. list.add(“one”);
Search WWH ::




Custom Search