CPSC426 Java EH421
Exercise/Homework EH42
Q1: The collections framework algorithms are ______, i.e., each of these algorithms can operate on objects that offer given interfaces without concern to the underlying implementations.
- Stable.
- Lexicographical.
- Polymorphic.
- Implementation dependent.
ANS:
Q2: Collections methodsortthat accepts a List as an argument sorts the elements of a List, which must implement the______interface.
- Comparable.
- Comparator.
- Compare.
- Ordering.
ANS:
Q3: Collections method ______returns a Comparator object that orders the collection’s elements in reverse order.
- rotate.
- shuffle.
- reverse.
- reverseOrder.
ANS:
Q4: Comparator method compare should return ______if the first argument is greater than the second argument.
- a positive int value.
- zero.
- a negative int value.
- a String.
ANS:
Q5: Algorithm ______randomly orders a List's elements.
- random.
- randomsort.
- distribute.
- shuffle.
ANS:
Q6: Method shuffle is a member of ______.
- Class Arrays.
- Class Collections.
- Interface Collection.
- Interface List.
ANS:
Q7: Class Collections provides algorithms for reversing, filling and copying ______.
- Lists.
- Collections.
- Arrays.
- Stacks.
ANS:
Q8: To find the smallest and largest element of a Collection, use Collections methods ______and ______.
- least, greatest.
- small, large.
- first, last.
- min, max.
ANS:
Q9: If the desired Object is not found, binarySearch returns ______.
- A positive value
- Zero
- A negative value
- An ObjectNotFoundError.
ANS:
Q10: Which statement is false?
- Java does not guarantee which item will be found first when a binarySearch is performed on a List containing multiple elements equivalent to the search key.
- If the search key is found, method binarySearch returns the List index (position relative to 1) of the element containing the search key.
- The binary search algorithm is fast.
- Method binarySearch takes a List as the first argument.
ANS:
Q11: Among others, J2SE 5.0 includes three new collections algorithms. Which of the following is not a new algorithm?
- add.
- addAll.
- frequency.
- disjoint.
ANS:
Q12. Write a program that determines and prints the number of duplicate words in a sentence. Treat uppercase and lowercase letters the same. Ignore punctuation.
ANS: