Computer Science Arrays

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

length of an array

Use the method 'length' and you would do it to use it as the upper bound of a for loop or to avoid the ArrayIndexOutOfBoundsException.

the number of columns of the 2D array

Use the method 'length' on the 0 element of the first index,that is to say: arr[0].length. You would do it to use the value as the upper bound of columns of a for loop or to avoid theArrayIndexOutOfBoundsException.

Arrays use 0 as the first index

What is the one concept about arrays that will trip you up and haunt you the rest of your programming life?

get()

What method do I use to find out what is at a particular index:

ArrayIndexOutOfBoundsException

When you try and use an index that does not exist, in other words, the index is 'out of the bounds' of the possible indices.

What are the two ways to add elements to your list:

with just add() that will put it on the end of the list of add() with an index that will add your element in a place of your choosing

two dimensional array

A two dimensional array is a container object that holds a fixed number of values of a single type. but unlike the one dimensional array, the two dimensional array has is an array of arrays and store data in rows and columns. The length of each dimension of the array is established when the array is created. After creation, its length is fixed. Each item in an array is called an element, and each element is accessed by its numerical index.

array

An array is a container object that holds a fixed number of values of a single type. The length of an array is established when the array is created. After creation, its length is fixed. Each item in an array is called an element,and each element is accessed by its numerical index.

enhanced for loop

An enhanced for loop takes every element in the array, go through them from the first element, one at a time, to the last element, and give you the value of that element in a variable you created.

How do I change a value at a particular index: set()

How do I change a value at a particular index:

type[][] array = { {val1, val2, val3}, {val4, val5, val6} };

How do I declare, initialize and load the 2D array all at once?

type[] array = { val , val , val };

How do I declare, initialize and load the array all at once?

remove()

How do I get rid of a value at a particular index:

enhanced loop to display the elements of a 2D array

The outer loop returns 1D arrays (AKA: columns) and the inner loop returns elements

two steps needed to build an array

Just like primitive types, you need to declare the array and then initialize it. The only difference is that when you initialize it, you need to let the program know how many elements the array will have.

List

List<String> mylist1 = new ArrayList<String>();

toString(), .forEach, enhanced for loop, regular for loop

Tell me 4 ways to display the contents of the list:

Enhanced Loop

for (datatype[] rows : ArrayIn2D ) { for (datatype element : rows ) { System.out.print(element); } }

What is a List or ListArray:

it is a collection of a predefined class in Java that will allow you build and manage collections

How do you declare and initialize a List:

just like everything else


Set pelajaran terkait

4. A gazdálkodás alapegységei (4.2.6 A vállalkozási formák csoportosítása, egyéni vállalkozás)

View Set

EURO: AP EXAM SUICIDE MOSTER SET

View Set

Research Methods Exam 1 (Chap 1- 4)

View Set

MGT10001 - Introduction to Management Exam Prep

View Set

US Gov - Topic 3: The Judicial Branch

View Set

Ch. 9 Cultural Competence/Transcultural Nursing

View Set