unit 7 Flashcards
Arraylists are _____ (mutable/immutable)
mutable
how does an arraylist dynamically change size?
stores items in underlying array, creates bigger/smaller array and replaces old array with new one under same reference
define and write a “wild card” import of the java util class
imports all classes within a package (not specified, such as with import java.util.ArrayList;)
import java.util.*;
(true/false) referencing java.util.ArrayList
is the same as referencing ArrayList as a class name
true, but only after ArrayList has been imported, either via a wild card import or a single
import java.util.ArrayList;
statement
(true/false) import statements must come before a class definition
trueeee
how do you declare an arraylist?
ArrayList<Type> name;</Type>
in ArrayList<Type> name, type is a:</Type>
type parameter
in the statement:
ArrayList mystery = new Arraylist();
what type is the arraylist set to?
object type, as in:
ArrayList<object></object>
what types of data can ArrayLists hold? (primitives/references/ both)
references only, thus, for example, int must be converted to Int to be stored in an ArrayList
true/false: due to autoboxing, in arraylists Ints and Doubles are NOT able to be treated like ints and doubles
false; they can be approximately basically sorta mostly yearh
how to create arraylist
like all other reference variables, we must call a constructor. in this case, declare an arraylist:
ArrayList<String> myList;</String>
and set it equal to
new ArrayList<String>();</String>
what does the size() method do?
returns number of items in array
what happens if you call the size of list2 after the following initialization:
ArrayList<String> nameList = new ArrayList<String>();
?</String></String>
what about with
ArrayList<String> list2 = null; ?
- you get returned a 0, there is literally no element and thus size = 0
- returned a null, methods cannot be called on null
when are sequential searches used? when are binaries?
when you have a desired component in unsorted data
when you have data sorted in some manner
types of sorting algorithms (and their definitions)
- selection:
- insertion:
- merge: