Download Exercise/Homework EH41

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
CPSC426 Java
EH41
Exercise/Homework EH41
Q1: Which of these is not an example of a "real-life" collection?
a.The cards you hold in a card game.
b.Your favorite songs stored in your computer.
c.The players on a soccer team.
d.The number of pages in a book.
ANS:
Q2: The Java collections __________ provides standardized collections intended for broad reuse.
a.Frameset.
b.Framework.
c.Framegroup.
d.Frametable.
ANS:
Q3: Which statement is false?
a.A collection is an object that can hold references to other objects.
b.The collection interfaces declare the operations that can be performed on each type of collection.
c.Unfortunately, collections discourage software reuse because they are non-portable.
d.Collections are carefully constructed for rapid execution and efficient use of memory.
ANS:
Q4: The classes and interfaces which comprise the collections framework are members of package
________.
a.java.util.
b.javax.swing.
c.java.collections.
d.java.collection.
ANS:
Q5: Class Arrays methods sort, binarySearch, equals and fill are overloaded for primitivetype arrays and Object arrays. In addition, methods __________ and __________ are overloaded with
generic versions.
a.sort, binarySearch.
b.sort, fill.
c.binarySearch, equals.
d.binarySearch, fill.
ANS:
Q6: Class Arrays provides method __________ for comparing arrays.
a.compare.
b.compares.
c.equal.
d.equals.
ANS:
1
CPSC426 Java
EH41
2
Q7: Interface __________ allows a program to walk through the collection and remove elements from the
collection.
a.Set.
b.Queue.
c.Iterator.
d.List.
ANS:
Q8: Interface Collection contains __________ operations (i.e., operations performed on the entire
collection).
a.aggregate.
b.composite.
c.integral.
d.bulk.
ANS:
Q9: Which statement is false?
a.A List is an ordered Collection.
b.A List cannot contain duplicate elements.
c.A List is sometimes called a sequence.
d.Lists are zero based.
ANS:
Q10: Which of the following does not implement interface List?
a.ArrayList.
b.LinkedList.
c.Vector.
d.ListIterator.
ANS:
Q11: Which statement is false?
a.A ListIterator accesses the elements of a List.
b.Class ArrayList is a fixed-size array.
c.A LinkedList is a linked list implementation of a List.
d.ArrayLists execute faster than Vectors because they are not thread safe.
ANS:
Q12: Iterator method __________ determines whether the Collection contains more elements.
a.hasNext.
b.next.
c.contains.
d.containsNext.
ANS:
CPSC426 Java
EH41
Q13: LinkedList method listIterator returns a(n) __________.
a.Iterator.
b.List.
c.sub list.
d.bidirectional iterator.
ANS:
Q14: Which statement is false?
a.When a List is backed up with an array, any modifications made through the List view change
the array.
b.When a List is backed up with an array, any modifications made to the array change the List
view.
c.The only operation permitted on the view returned by Arrays method asList is delete, which
deletes the value from the view and the backing array.
d.Adding elements to the view returned by Arrays method asList results in an
UnsupportedOperationException.
ANS:
Q15: Vector method __________ determines the number of elements currently in the Vector.
a.capacity.
b.length.
c.size.
d.contains.
ANS:
Q16: Which statement is false?
a.If you do not specify a capacity increment for a Vector, the system will automatically choose a
default value of 10.
b.Inserting additional elements into a Vector whose current size is less than its capacity is a
relatively fast operation.
c.It is a relatively slow operation to insert an element into a Vector that needs to grow larger to
accommodate the new element.
d.A reference to an object of any class type can be stored in a Vector.
ANS:
3
CPSC426 Java
EH41
Q17: Write a program that reads in a series of first names and stores them in a LinkedList. Do not store
duplicated names. Allow the user to search for a first name.
4