Question: 1 . An advantage of using the ArrayList class over the Arrays class is that an ArrayList . a . can hold more elements b

1. An advantage of using the ArrayList class over the Arrays class is that an ArrayList .
a.can hold more elements
b. is dynamically resizable
c. supports use with indexes
d. requires less memory
2. An ArrayList can hold .
a. any primitive type
b. any numeric type
c. any object type
d. only 10 objects
3. The number of items an ArrayList can hold is its .
a. sufficiency
b. scope
c. range
d. capacity
4. If you have declared an ArrayList of Strings named myStrings, which of the following is not a legal method call?
a. myStrings.add("onion");
b. myStrings.remove("onion");
c. int s = myStrings.size();
d. myStrings.add(0, "leek");
5. Suppose you have declared an ArrayList of Integers named numbers with a capacity of 10, and that you have assigned values to the first six elements. Which of the following is not legal?
a. numbers.get(9);
b. numbers.set(1,55);
c. numbers.get(5);
d. numbers.add(77);
6. When you create a class from which you will instantiate objects to store in an ArrayList, .
a. you must create a toString() method
b. you must create a compareTo() method
c. you must create both a toString() method and a compareTo() method
d. you are not required to create either a toString() method or a compareTo() method
7. The method that can be used to sort an ArrayList is .
a. Collections.sort()
b. ArrayList.sort()
c. List.sort()
d. Sorting.sort()
8. All of the following classes contain a built-in compareTo() method except .
a. Integer
b. String
c. Scanner
d. Double
9. If you want to use Collections.sort() with a class you have created, you must .
a. write your own compareTo() method
b. overload the < and > operators
c. write your own toString() method
d. write both a compareTo() method and toString() method
10. Which is not a requirement when you create a compareTo() method that overrides the Object class compareTo() method?
a. It must accept a parameter.
b. Its return type must be boolean.
c. It should return a value that is 1,0, or 1.
d. It must be named compareTo().
11. Suppose you have created a Student class compareTo() method that is based on the value of a private idNum field.
Assume the class contains a public getId() method that returns the idNum value. Also suppose that stu1s idNum is 345 and that stu2s idNum is 456.
Which of the following returns 1?
a. stu1.compareTo(stu2)
b. stu2.compareTo(stu1)
c. stu2.compareTo(stu1.idNum)
d. stu1.getId().compareTo (stu2.getId())
11. Which of the following is true?
a. The ArrayList class works better than a LinkedList when you must move a lot of the data stored there.
b. The ArrayList class works better than a LinkedList when you have to sequentially retrieve a lot of data.
c. An ArrayList always works more efficiently than a LinkedList.
d. An ArrayList always is less efficient than using a LinkedList.
12. An object that can be used in a foreach loop to process the elements in a Collection is a(n).
a. index
b. subscript
c. repeater
d. iterator
13. A generic class is one that uses a(n).
a. overloaded method
b. generic method
c. type parameter
d. empty method
14. A generic method .
a. resides in a generic class
b. cannot be overloaded
c. can contain only one parameter
d. uses at least one type parameter
15. A generic method .
a. must have a type parameter that represents a reference type
b. must return a generic parameter
c. must have an empty body that is created at runtime
d. can have no more than one type parameter

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!