Question: Java Question 5. To change the size of an array list, you must a. code a statement that specifies the new number of elements b.
Java Question
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
Get step-by-step solutions from verified subject matter experts
