Ch 6.8

¡Supera tus tareas y exámenes ahora con Quizwiz!

Java 7 introduced enhanced syntax for declaring array lists, which is termed _________________. symmetric slants angle brackets diamond syntax method lists

diamond syntax

Which one of the following is the correct code snippet for calculating the largest value in an integer array list arrList of size 10? int maximum = arrList.get(0); for (int counter = 1; counter < arrList.size(); counter++) { if (arrList.get(counter) > maximum) { maximum = arrList.get(counter); } } int maximum = arrList.get(0); for (int counter = 1; counter > arrList.size(); counter++) { if (arrList.get(counter) < maximum) { maximum = arrList.get(counter); } } int maximum = arrList.get(1); for (int counter = 1; counter < arrList.size(); counter++) { if (arrList.get(counter) > maximum) { maximum = arrList.get(counter); } } int maximum = 0; for (int counter = 1; counter < arrList.size(); counter++) { if (arrList.get(counter) > maximum) { maximum = arrList.get(counter); } }

int maximum = arrList.get(0); for (int counter = 1; counter < arrList.size(); counter++) { if (arrList.get(counter) > maximum) { maximum = arrList.get(counter); } }

Consider the following line of code for calling a method named func1: func1(listData, varData); Which one of the following method headers is valid for func1, where listData is an integer array list and varData is an integer variable? public static void func1(int[] listData, int varData) public static void func1(ArrayList<Integer> ldata, int vdata) public static void func1(int vdata, ArrayList<Integer> ldata) public static void func1(ArrayList<Integer> listData, varData)

public static void func1(ArrayList<Integer> ldata, int vdata)

Consider the following code snippet: ArrayList<Double> somedata = new ArrayList<Double>(); somedata.add(10.5); What is the size of the array list somedata after the given code snippet is executed? 10 2 0 1

1

What is the output of the following statements? ArrayList<String> names = new ArrayList<String>(); names.add("Bob"); names.add(0, "Ann"); names.remove(1); names.add("Cal"); names.set(1, "Tony"); for (String s : names) { System.out.print(s + ", "); } Ann, Tony Cal, Bob, Ann Ann, Bob Cal, Bob, Tony

Ann, Tony

Which statement represents the shortcut diamond syntax for declaring and constructing array lists? ArrayList<Double> values = new ArrayList<>(); ArrayList<Double> values = new ArrayList<Double>; ArrayList<Double> values = new ArrayList<Double>(); ArrayList<> values = new ArrayList<Double>();

ArrayList<Double> values = new ArrayList<>();

Consider the following code snippet: ArrayList<Integer> arrList = new ArrayList<Integer>(); for (int i = 0; i < arrList.size(); i++) { arrList.add(i + 3); } What value is stored in the element of the array list at index 0? 0 3 None 6

None

What should you check for when calculating the largest value in an array list? The array list contains at least one element. The array list contains the maximum value in the first element. The array list contains at least two elements. The array list contains the minimum value in the first element

The array list contains at least one element.

Consider the following code snippet, where the array lists contain elements that are stored in ascending order: ArrayList<Integer> list1 = new ArrayList<Integer>(); ArrayList<Integer> list2 = new ArrayList<Integer>(); . . . int count = 0; for (int i = 0; i < list1.size() && i < list2.size(); i++) { if (list1.get(i) == list2.get(i)) { count++; } } Which one of the following descriptions is correct for the given code snippet? The code snippet adds the values of the two array lists. The code snippet finds the lowest value out of the two array lists. The code snippet finds the highest value out of the two array lists. The code snippet compares the values of two array lists and stores the count of total matches found.

The code snippet compares the values of two array lists and stores the count of total matches found.

Which statement is true about the code snippet below? ArrayList<String> names = new ArrayList<String>(); names.add("John"); names.add("Jerry"); ArrayList<String> friends = new ArrayList<String>(names); friends.add("Harry"); Compilation error The final size of names is 3; the final size of friends is 3 The final size of names is 3; the final size of friends is 2 The final size of names is 2; the final size of friends is 3

The final size of names is 2; the final size of friends is 3


Conjuntos de estudio relacionados

ch.13 Inequality, Social Insurance, and Redistribution

View Set