Ch 7: Arrays and the ArrayList Class

Ace your homework & exams now with Quizwiz!

T or F: When an array of objects is declared, but not initialized, the array values are set to null.

True

T or F: If a[ ] and b[ ] are two integer arrays, the expression a == b compares the array contents.

False

A search algorithm:

Is a way to locate a specific item in a larger collection of data

T or F: The purpose of the sequential search algorithm is to rearrange the elements of an array so they appear in order from the lowest value to the highest value.

False

What does the following statement do? double[] array1 = new double[10]; A. Declares array1 to be a reference to an array of double values B. Creates an instance of an array of 10 double values C. Will allow valid subscripts in the range of 0-9 D. All of these

D. All of these

What will be the result of executing the following code? int[] x = {0, 1, 2, 3, 4, 5}; A. An array of 6 values ranging from 0-5 and referenced by the variable x will be created B. A compilation error will occur C. The program will crash when it is executed D. The value of x[1] will be 0, x[2] will be 0, x[3] will be 0, x[4] will be 0, x[5] will be 0, and x[6] will be 0

A. An array of 6 values ranging from 0-5 and referenced by the variable x will be created

The sequential search algorithm:

Uses a loop to sequentially step through an array, starting with the first element

T or F: An ArrayList object automatically expands in size to accommodate the items stored in it.

True

T or F: Any items typed on the command-line, separated by space, after the name of the class are considered to be one or more arguments that are to be passed into the main method.

True

T or F: To compare the contents of two arrays, you must compare the elements of the two arrays.

True

You can use this ArrayList class method to insert an item at a specific location in an ArrayList.

add

You can use this ArrayList class method to replace an item at a specific location in an ArrayList.

add???

The ArrayList class is in this package.

java.util

If numbers is a two-dimensional array, which of the following would give the length of row r?

numbers[r].length

Given that String[ ] str has been initialized, to get a copy of str[0] with all characters converted to upper case, use the following statement:

str[0].toUpperCase( );

What would be the results of the following code? final int SIZE = 25; int[ ] array1 = new int[SIZE]; ... // Code that will put values in array1 int value = 0; for(int a = 0; a < array.lenth; a++) { value += array1[a]; }

value contains the highest value in array1

How many rows and how many columns are in the points array, declared here: int [ ][ ] points = new int[10][20];

10 rows and 20 columns

What will be the value of x[8] after the following code has been executed? final int SUB = 12; int[ ] x = new int[SUB]; int y = 100; for(int i = 0; i < SUB; i++) { x[i] = y; y+= 10; }

180

Which of the following is a valid declaration for a ragged array, after which you would declare each row? A. int[ ] ragged = new int[5]; B. int[ ][ ] ragged = new int[5][6]; C. int[ ][ ] ragged = new int[5][ ]; D. int[ ][ ] ragged = new int[ ][5];

C. int[ ][ ] ragged = new int[5][ ];

T or F: Java limits the number of dimensions that an array may have to 15.

False

The following statement creates an ArrayList object. What is the purpose of the <String> notation? ArrayList<String> arr = new ArrayList<String>( ); A. It specifies that only String objects may be stored in the ArrayList object B. It specifies that the get method will return only String objects C. It specifies that String objects may not be stored in the ArrayList object D. It specifies that everything stored in the ArrayList object will be converted to a String

A. It specifies that only String objects may be stored in the ArrayList object

What will be the results of the following code? final int ARRAY_SIZE = 5; float [ ] x = float[ARRAY_SIZE]; for(int i = 1; i <= ARRAY_SIZE; i++) { x[i] = 10.0; }

An error will occur when the program runs

Which of the following is a correct method header for receiving a two-dimensional array as an argument? A. public static void passArray(int[1,2] intArray) B. public static void passArray(int [ ][ ] intArray) C. public static void passArray(int[1],[2] intArray) D. public static void passArray(int[ ], int[ ]intArray)

B. public static void passArray(int [ ][ ] intArray)

What is the value of scores[2][3] in the following array? int [ ] [ ] scores = { {88, 80, 79, 92}, {75, 84, 93, 80}, {98, 95, 92, 94}, {91, 84, 88, 96} };

94

A ragged array is:

A two-dimensional array when the rows are of different lengths


Related study sets

Estructura 2.4 Numbers 31 and higher: Baloncesto. Baloncesto. Fill in the blanks with the basketball scores in Spanish. Follow the model.

View Set

PSYC4050 L.7 Logistic Regression

View Set

Part Two: Scientific Basis for Practice

View Set

Chapter 28 Care of the Pt Requiring Oxygen Therapy or Tracheostomy

View Set

sociology chapter 14 and 15. review

View Set

Health Economics Final (chpt 1-5,11,12)

View Set

MAN3027- Lesson 07- Innovation & Change

View Set

Meaning and Characteristics of Italian Renaissance UNIT 1

View Set

Topic 8A: Configure Workstation Security

View Set

(21/11) formation of t and b cells

View Set

Topic 9 (Other Assurance and Non-Assurance Services)

View Set

Social Psychology Key Question: HOW CAN KNOWLEDGE OF SOCIAL PSYCHOLOGY BE USED TO REDUCE PREJUDICE IN SITUATIONS SUCH AS CROWD BEHAVIOUR OR RIOTING?

View Set