CS Chapter 7 Arrays and the ArrayList Class

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

diamond operator

(< >) used to simplify the instantiation of an ArrayList

How do you insert an item at a specific location in the ArrayList object?

ArrayList class has an overloaded version of the add method that allows you to add an item at a specific index. Ex.) List.add(1, "Mary");

Write a statement that creates an ArrayList object and assigns its address to a variable named frogs

ArrayList frogs = new ArrayList();

Write a statement that creates and ArrayList object and assigns its address to a variable named lizards. The ArrayList should be able to accept String objects only.

ArrayList<String>lizards = new ArrayList<String>();

How do you remove an item from an ArrayList object?

List.remove(index);

What is the difference between an array's size declarator and a subscript?

The size declarator is used in the array declaration statement. It specifies the number of elements in the array. A subscript is used to access an individual element in an array.

How does selection sort work?

The smallest value in the array is located and moved to element 0. Then the next smallest value is located and moved to element 1. This is process continues until all of the elements have been placed in their proper order.

ArrayList

a class in the Java API that is similar to an array and allows you to store objects. Unlike an array, this object's size is automatically adjusted to accommodate the number of items being stored in it.

search algorithm

a method of locating a specific item in a larger collection of data

two-dimensional array

an array of arrays. it can be thought of as having rows and columns.

one-dimensional array

array that can only hold one set of data

subscript

each element in an array is assigned this number. It is used as an index to pinpoint a specific element within an array.

What import statement must you include in your code to use the ArrayList class?

import java.util.ArrayList;

array

list of data elements; object that needs an object reference

enhanced for loop

specialized version of the for loop that, in many circumstances, simplifies array processing. it's designed to iterate once for every element in an array. Each time the loop iterates, it copies an array element to a variable.

vararg parameter

the ellipsis that follows the data type indicates that numbers is a special type of parameter

size declarator

the number inside the brackets of an array

capacity

the number of items that an ArrayList object can store without having to increase its size

An array is accessed by:

the reference name a subscript that identifies which element in the array to access

sorting algorithm

this is used to arrange data into some order

variable-length argument lists

this makes it possible to write a method that takes a variable number of arguments

An array can be passed as an argument to a method. true or false?

true

subscript numbering always starts at 0. true or false?

true

subscript numbers can be stored in variables. true or false?

true

How do you add items to an ArrayList object?

with add method

What would the valid subscript values be in a four-element array of doubles?

0 through 3

What is the output of the following code? int values[5], count; for (count = 0; count < 5; count++) values[count] = count + 1; for (int count = 0; count < 5; count++) System.out.println(values[count]);

1 2 3 4 5

What is the difference between an ArrayList object's size and its capacity?

Size=number of items stored in the Array List object. Capacity=number of items an ArrayList object can hold without having to increase its size.

How do you retrieve a specific item from an ArrayList obejct?

The ArrayList class has a get method that retrieves an item at a specific index. We pass the index as an argument to the method. Ex.) List.get(3);

How do you determine an ArrayList object's size?

The ArrayList class has a size method that returns the number of items stored in the ArrayList.


Conjuntos de estudio relacionados

International Relations Chapters 8-10

View Set

Bahasa Indonesian Hello, Goodbye, Well Wishes

View Set

Psych 2035 chapter 11 Gender and behaviour

View Set

Hello, Universe Vocabulary List (chapters 1-19)

View Set

¡Hola!, Números del 0 al 10, ¿Cómo estás?

View Set

Causes of Imperialism (Imperialism)

View Set

AF Heritage and Values Midterm Fall 2020

View Set