Java Ch7 Arrays and the ArrayList Class

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

Enhanced For Loop

for(dataType elementVariable: array) statement; variable declaration= must be of the same data type or of one that can be automatically converted for ( int val: numbers) System.out.println(val); Loop that: Does not require an index Is not concerned about the size of array Can't change contents, reverse order, access discriminately, work with two arrays, or refer to the subscript number of a particular element

Sequential Search Algorithm

A method of locating a specific item in a larger collection of data in an array. Compares search values bitwise and margins of error need to be considered when matching floating point values.

Sorting Algorithm

A technique for scanning through an array and rearranging its contents in some specific order.

final variable

A type of variable we use for size declarators so that the contents cannot be changed during the program's execution. NOTE: Once an array is created, its size cannot be changed.

Initialization List

Alternative form of declaring an array and initializing the arrays elements without using the keyword new. EX: int[] days= {31, 34 ,234, 45, 56 ,2 23, 45};

Subscript

Although an array has one name the elements in the array may be accessed and used as individual variables. This is achieved through index to pinpoint specific elements within an array call a _______

Selection Sort

An algorithm that locates the smallest value in an array and moves it to element zero, next smallest value is moved to element one, and so forth until all the values are arranged in their proper order.

References

An array of String objects is really an array of ______ to String objects.

Two Dimensional array

An array of arrays, declared by: double [] [] scores = new double[3] [4]; row major column Other initialization forms: int [] [] numbers = { {1,2,3}, {4,5,6}, {7,8,9} };

runtime

Bounds checking in Java occurs in _______.

zero

By default, Java initializes array elements with _

By reference

How the array is passed into the method, just as an object is passed:

add Method

Method belonging to ArrayList class that adds an item at a specific index and pushes the items in the array to higher index values. Ex: nameList.add(1, "Bitch")

toString Method

Method belonging to ArrayList class that returns a string representing all the items stored in an ArrayList object.

Binary Search Algorithm

More efficient search algorithm than the sequential search algorithm. Starts by going to the middle of a list that needs to be ranked in ascending order. If the value is higher than the value being searched then it searches the upper half of the numbers (vice versa for a lower number) and saves 1/2 the time. 1/2 the array's elements are eliminated in the search and repeats on diminishing halves.

Vararg Parameter

Parameter that can take a variable number of arguments. Ex: public static int sum(int... number) or public static void courseAverage(String course, double... scores) All of the arguments passed are actually put into the numbers array and stored as an array of ints.

ArrayIndexOutOfBoundsException

Runtime error thrown when programmer writes a statement that uses an invalid subscript not in the range of the array size.

ArrayList

Special Java API provided class that can be used for storing and retrieving objects, similar to an array of objects. It can: Automatically expand items added to it Remove the items Autoshrinks as the items are removed Created by: ArrayList<String> nameList = new ArrayList<String>();

Size declarator

The number inside the brackets of an array reference variable declaration. Must be a non-negative integer. int [3] numbers;

Capacity

The term for the ArrayList object's size. It is initialized to 10 when the constructor is called but can be changed. Example: ArrayList<String> list = new ArrayList<String>(capacity)

Reference Copy

This type of assignment is called ____ ____ Ex; int [] array1 = {1,2,3,4,5}; int {} array2 = array1; //this does not copy array1 because arrays are objects so the reference variable and the object are two separate entities.

Accumulator Variable

To sum the values in an array you must use a loop with an ______ _______.

Memory addresses

When you use the == operator with reference variables, including those that reference arrays, the operator compares _______ __________ that the variables contain, not the contents of the objects referenced by the variables.

Off by One errors

Error that arises when iterating through an array starting at 1 instead of 0. Ex: final int SIZE = 100; int [] numbers = new int[SIZE]; for (int index = 1; index<SIZE; index ++) numbers[index] = 0; Code attempts to create an array and then assign the value zero to all the items in the array, it will throw and error because it ends at 100 when the array goes from 0 to 99.

Alternate Array Declaration

int [] numbers; int numbers[]; int[] numbers, codes, scores; //all ref. to int arrays int number[], cod, sco; //only numbers is array, rest int. int numbers [], codes [], scores []; // valid


Kaugnay na mga set ng pag-aaral

Ch 21: Inventory Management, Just-in-Time, and Simplified Costing Methods

View Set

Pharm Competency 3: Antipsychotics

View Set

Principles of Business - Marketing - Terms of Sale

View Set

Prep U Chapter 34: Assessment and Management of Patients with Inflammatory Rheumatic Disorders

View Set

Chapter 8: Digestive System and Nutition

View Set

moodle quizzes for exam 1 - econ 101

View Set

Interpersonal Communications Unit 6

View Set