Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Beginning Java with NetBeans: Chapter 14 How to work with collections, generics, and lambdas MULTIPLE CHOICE [Answers are in tables delete all but the correct

Beginning Java with NetBeans: Chapter 14

How to work with collections, generics, and lambdas

MULTIPLE CHOICE [Answers are in tables delete all but the correct answers cell]

1. Which of the following is not a difference between arrays and collections?

a. Collections can grow in size, but arrays cant.

b. Arrays can store unwrapped primitive types, but collections cant.

c. Arrays can store user-defined objects, but collections cant.

d. Collections are created from classes, but arrays arent.

2. Which of the following is not true of generics?

a. It can restrict the objects that are stored in a collection to a specific type.

b. It can be used to create collections that store primitive types.

c. It uses angle brackets (<>) to specify type information.

3. Which of the following statements creates an array list that can store double values?

a. ArrayList sales = new ArrayList<>();

b. ArrayList sales = new ArrayList();

c. ArrayList sales = new ArrayList();

d. ArrayList sales = new ArrayList<>();

4. Which of the following statements can be used to create an array list prior to Java 7?

a. ArrayList sales = new ArrayList<>();

b. ArrayList sales = new ArrayList();

c. ArrayList sales = new ArrayList();

d. ArrayList sales = new ArrayList<>();

5. To change the size of an array list, you must

a. code a statement that specifies the new number of elements

b. code a statement that specifies the percent by which you want the size increased

c. either a or b

d. none of the above

6. What is the initial capacity of the array list that follows?

ArrayList quantities = new ArrayList<>(20);

a. 10

b. 20

c. 31

d. 40

e. 41

7. What is the value of s after the following code is executed?

ArrayList inventory = new ArrayList<>();

String item = "Computer";

inventory.add(item); inventory.add("Printer"); inventory.add("Monitor");

inventory.add(1, "Mouse"); String s = inventory.get(2); a.Laptop

b. Printer

c. Computer

d.

8. What is printed to the console when the code that follows is executed?

ArrayList passwords = new ArrayList<>();

passwords.add("akjdk12");

passwords.add("buujl32");

passwords.add("chrcl92");

passwords.add("nnnii87");

passwords.set(2, "cb2kr45");

passwords.remove("akjdk12");

System.out.println(passwords.get(1));

a. buuj132

b. akjdk12

c. cb2kr45

d. nnnii87

9. What is the value of m after the code that follows is executed?

ArrayList miles = new ArrayList<>();

miles.add(37.5); miles.add(26.2); miles.add(54.7);

double m = miles.remove(0);

a.37.5

b. 26.2

c. 54.7

10. If an array list has 500 elements, how many elements will need to be moved to insert an element into position 100?

a. 0

b. 100

c. 2

d. 400

11. What happens when the code that follows is executed?

LinkedList units = new LinkedList<>();

units.add(8); units.add(12); units.add(3);

System.out.println(units.get(1));

a. 8 is printed to the console.

b. 12 is printed to the console.

c. A runtime error occurs because the add method cant wrap the int value in the Integer class.

d. A compile-time error occurs due to a syntax error.

12. Lambda expressions

a. Allow you to treat data like interfaces.

b. Make stack traces easier to understand.

c. Can allow you to write methods that are more flexible and easier to maintain.

d. Work well with the integrated debugger.

COMPLETION

13. The collection framework is made up of two class hierarchies named Collection and ________.

14. Prior to Java 7, you needed to code the type for a typed collection twice to create the collection. With Java 7 and later, you can use the ____________ operator instead of coding the type a second time.

15. The ArrayList class uses an ______________ internally to store the elements in the list.

16. Java uses a technique called ______________ to automatically add wrapper classes for primitive types whenever necessary.

17. Collections that store one or more key-value pairs are called ________.

18. A/an ________________ interface is an interface that only contains one method.

19. A/an ________________ can be passed as an argument to a method that accepts a functional interface as a parameter.

20. The Predicate interface uses _____________ to specify the type of object thats passed to its test method.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Google Analytics 4 The Data Driven Marketing Revolution

Authors: Galen Poll

2024th Edition

B0CRK92F5F, 979-8873956234

More Books

Students also viewed these Databases questions