19.3 |
Define each of the following terms:
- Collection
- Collections
- Comparator
- List
- load factor
- collision
- spacetime trade-off in hashing
- HashMap
|
19.4 |
Explain briefly the operation of each of the following methods of class Vector:
- add
- insertElementAt
- set
- remove
- removeAllElements
- removeElementAt
- firstElement
- lastElement
- isEmpty
- contains
- indexOf
- size
- capacity
|
19.5 |
Explain why inserting additional elements into a Vector object whose current size is less than its capacity is a relatively fast operation and why inserting additional elements into a Vector object whose current size is at capacity is a relatively slow operation.
|
19.6 |
By extending class Vector, Java's designers were able to create class Stack quickly. What are the negative aspects of this use of inheritance, particularly for class Stack?
|
19.7 |
Briefly answer the following questions:
- What is the primary difference between a Set and a Map?
- Can a two-dimensional array be passed to Arrays method asList? If yes, how would an individual element be accessed?
- What happens when you add a primitive type (e.g., double) value to a collection?
- Can you print all the elements in a collection without using an Iterator? If yes, how?
|
|
|
19.8 |
Explain briefly the operation of each of the following Iterator-related methods:
- iterator
- hasNext
- next
|
19.9 |
Explain briefly the operation of each of the following methods of class HashMap:
- put
- get
- isEmpty
- containsKey
- keySet
|
19.10 |
Determine whether each of the following statements is true or false. If false, explain why.
- Elements in a Collection must be sorted in ascending order before a binarySearch may be performed.
- Method first gets the first element in a treeSet.
- A List created with Arrays method asList is resizable.
- Class Arrays provides static method sort for sorting array elements.
|
19.11 |
Explain the operation of each of the following methods of the Properties class:
- load
- store
- getProperty
- list
|
19.12 |
Rewrite lines 1726 in Fig. 19.4 to be more concise by using the asList method and the LinkedList constructor that takes a Collection argument.
|
19.13 |
Write a program that reads in a series of first names and stores them in a LinkedList. Do not store duplicate names. Allow the user to search for a first name.
|
19.14 |
Modify the program of Fig. 19.20 to count the number of occurrences of each letter rather than of each word. For example, the string "HELLO THERE" contains two Hs, three Es, two Ls, one O, one T and one R. Display the results.
|
19.15 |
Use a HashMap to create a reusable class for choosing one of the 13 predefined colors in class Color. The names of the colors should be used as keys, and the predefined Color objects should be used as values. Place this class in a package that can be imported into any Java program. Use your new class in an application that allows the user to select a color and draw a shape in that color.
|
19.16 |
Write a program that determines and prints the number of duplicate words in a sentence. Treat uppercase and lowercase letters the same. Ignore punctuation.
|
19.17 |
Rewrite your solution to Exercise 17.8 to use a LinkedList collection.
|
19.18 |
Rewrite your solution to Exercise 17.9 to use a LinkedList collection.
|
19.19 |
Write a program that takes a whole number input from a user and determines whether it is prime. If the number is not prime, display the unique prime factors of the number. Remember that a prime number's factors are only 1 and the prime number itself. Every number that is not prime has a unique prime factorization. For example, consider the number 54. The prime factors of 54 are 2, 3, 3 and 3. When the values are multiplied together, the result is 54. For the number 54, the prime factors output should be 2 and 3. Use Sets as part of your solution.
|
19.20 |
Write a program that uses a StringTokenizer to tokenize a line of text input by the user and places each token in a treeSet. Print the elements of the treeSet. [Note: This should cause the elements to be printed in ascending sorted order.]
|
19.21 |
The output of Fig. 19.17 (PriorityQueueTest) shows that PriorityQueue orders Double elements in ascending order. Rewrite Fig. 19.17 so that it orders Double elements in descending order (i.e., 9.8 should be the highest-priority element rather than 3.2).
|