array list Flashcards

1
Q

generics

A

effectively build a template than can be instantiated in many ways (form of polymorphism)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

declare an array list

A

ArrayList arrName;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

create a new ArrayList object and store the reference.

A

arrName = new ArrayList();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

how to add objects to an array list

A
arrName.add(1.1F); 
or
Float f = new Float(3.14F); arrName.add(f);
or specify position 
arrName.add(2.3F);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

how to remove items from array list

A

arrName.remove(three);
use reference to the object in list (returns Boolean (if that item was in the list or not))
or
arrName.remove(1);
specify its 0-based index position number in list ( returns a reference to removed object)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

contains method

A

(arrName.contains(seek));

returns a Boolean value indicating whether that object is in the list.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

get method

A

returns a reference to the object at the 0-based index position
Student ref = myStudents.get(3); ref.setUID(987654321);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

to find the current length of an array

A

int length = arrName.size();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

iterate through array list

A

int length = arrName.size(); for (int i=0; I

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

shallow copy array list code

A

ArrayList newArr; newArr = new ArrayList(oldArr);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

for each loop

also allows us to iterate through array lists

A

for (Typename iteratedVal : collection) { //process the iteratedVal object
}

NOTE: You cannot alter the structure of a list while iterating through it using a for-each style loop!!!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

deep copy array list code

A
ArrayList dupList;
dupList = new ArrayList();
for (StringBuffer str : origList) {
dupList.add(new StringBuffer(str));
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly