JAVA Unit 9 Arraylists

Ace your homework & exams now with Quizwiz!

Retrieving value. Array or array list? String s = list.get(0);

Arraylist

Collections.reverse()

Reverse order of arraylist

Collections.sort(list, Comparator.comparing(s -> s.getX()))

Sort an arraylist using a specific key

boxing

Taking a primitive data element and wrapping it up in a wrapper class Ex. Double myDouble = new Double(6.0);

unboxing

Taking the primitive out of the wrapper Ex. double myPrimitive = myDouble.doubleValue();

Wrapper.typeValue()

Template for getting the primitive value in a wrapper.

Wrapper.parseType()

Template for parsing a value into a wrapper

<Class>

When constructing an ArrayList, you must specify the type of elements it will contain between < and >. (also called type parameter)

list

a collection storing an ordered sequence of elements

add(value)

appends value at end of list

add(index, value)

inserts given value just before the given index, shifting subsequent values to the right

size

number of element that have been added

Wrapper

object whose sole purpose is to hold a primitive value

clear()

removes all elements of the list

remove(index)

removes/returns value at given index, shifting subsequent values to the left

set(index, value)

replaces value at given index with given value

toString()

returns a string representation of the list such as "[3, 42, -7, 15]"

indexOf(value)

returns first index where given value is found in list (-1 if not found)

toArray() list.toArray();

returns the elements in this list as an array

size()

returns the number of elements in list

get(index)

returns the value at given index

equals(list)

returns true if given other list contains the same elements

contains(value)

returns true if given value is found somewhere in this list


Related study sets

Wk 6 Practice Global Environments

View Set

Social Security (Life Insurance)

View Set

Prep U: Fluid, Electrolyte and Acid-Base Balance

View Set

Physics Review - Circular Motion

View Set

modern italian architecture 4:futurism

View Set

Chapter 10 test: internet law and privacy

View Set

What will you be doing next weekend?

View Set