Ch. 7 - Arrays and the ArrayList Class

Ace your homework & exams now with Quizwiz!

Java performs ____________, which means that it does not allow a statement to use a subscript that is outside the range of valid subscripts for the array.

Array bounds checking

TRUE/FALSE: A sorting algorithm is used to locate a specific item in a larger collection of data.

False

TRUE/FALSE: An array can hold multiple values of several different data types simultaneously.

False

TRUE/FALSE: If a[] and b[] are two integer arrays, the expression a == b compares the array contents.

False

TRUE/FALSE: Java limits the number of dimensions that an array may have to 15.

False

In Java, you do not use the new operator when you use an:

Initialization list

In order to do a binary search on an array:

The array must first be sorted in ascending order

TRUE/FALSE: 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

TRUE/FALSE: Declaring an array reference variable does not create an array.

True

TRUE/FALSE: Java does not limit the number of dimensions that an array may have.

True

TRUE/FALSE: Objects in an array are accessed with subscripts, just like any other data type in an array

True

TRUE/FALSE: Once an array is created, its size cannot be changed.

True

TRUE/FALSE: The String[] args parameter in the main method header allows the program to receive arguments from the operating system command-line.

True

The binary search algorithm:

Will cut the portion of the array being searched in half each time the loop fails to locate the search value

It is common practice to use a ____________ variable as a size declarator.

final

The ArrayList class is in this package.

java.util

Each array in Java has a public field named ____________ that contains the number of elements in the array.

length

To return an array of long values from a method, use this as the return type for the method.

long[]

You use this method to determine the number of items stored in an ArrayList object.

numberItems

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

numbers[r].length

Which of the following is a correct method header for receiving a two-dimensional array as an argument?

public static void passArray(int [][])

This ArrayList class method deletes an item from an ArrayList.

remove

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

set

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 do you call the number that is used as an index to pinpoint a specific element within an array?

subscript

By default, Java initializes array elements with what value?

0

Subscript numbering always starts at what value?

0

If final int SIZE = 15 and int[] x = new int[SIZE], what would be the range of subscript values that could be used with x[]?

0 through 14

For the following code, what would be the value of str[2]? String[] str = {"abc", "def", "ghi", "jkl"};

A reference to the String "ghi"

A ragged array is:

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

When an array is passed to a method:

All of the above (A reference to the array is passed, It is passed just as an object, & The method has direct access to the original array)

What does the following statement do? double[] array1 = new double[10];

All of the above (Declares array1 to be a reference to an array of double values, Creates an instance of an array of 10 double values, & Will allow valid subscripts in the range of 0 - 9)

What do you normally use with a partially-filled array?

An accompanying integer value that holds the number of items stored in the array

What will be returned from the following method? public static float[] getValue(int x)

An array of float values

A search algorithm:

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

The following statement creates an ArrayList object. What is the purpose of the <String> notation? ArrayList<String> arr = new ArrayList<String>();

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

TRUE/FALSE: A sorting algorithm is a technique for scanning through an array and rearranging its contents in some specific order.

True

TRUE/FALSE: An ArrayList object automatically expands in size to accommodate the items stored in it.

True

TRUE/FALSE: To compare the contents of two arrays, you must compare the elements of the two arrays.

True

TRUE/FALSE: When an array of objects is declared, but not initialized, the array values are set to null.

True

The sequential search algorithm:

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

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

This ArrayList class method is used to insert an item into an ArrayList.

add

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

add

In memory, an array of String objects:

Consists of elements, each of which is a reference to a String object

This indicates the number of elements, or values, the array can hold.

The array's size declarator

When an individual element of an array is passed to a method:

The method does not have direct access to the original array


Related study sets

Psychology: Chapter 4 Study Guide

View Set

OT Survey: Poetry and Prophecy study guide

View Set

Chapter 2- Product Development Process and Organization

View Set

Pathophysiology Review Questions

View Set