collection and collections Flashcards

1
Q

collection interface

A

Java standard install, a generic interface called Collection which identifies some common methods for interacting with such data structures

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

collections class

A

Java standard install, classcalled Collectionswhich includes some potentially useful static methods that can interact with Collection-based objects

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

7 of the Collection methods

A
boolean add(E newVal)
 void clear() 
boolean contains(Object ref)
boolean remove(Object ref)
int size() 
boolean isEmpty() 
Object[] toArray()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

3 classes that implement Collection

A

ArrayList, PriorityQueue, Stack

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

PriorityQueue

A

removes the smallest item every time you call remove()

handy for printing things smallest to largest:System.out.println(myFloatPQ.remove())

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

collection interface benefits:

A

> a method that should be able to operate on multiple objects

>you can write the method to take a reference to any object that implements that interface!

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

collection interface cons:

A

Java allows you to access data structures in other ways as well
(less secure)

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

methods that can take arraylists object’s reference

A
> ArrayList class implements List which extends Collection
> any method which can take either a List or a Collection as a parameter  (methods in collection do this)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

sort

A

Collections.sort(myList);

use our compareTomethod as the basis for sorting the list behind the scenes.

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

min, max

A

could print the record of the students with the alphabetically smallest and largest name: System.out.println(“Min: “+Collections.min(myList));
System.out.println(“Max: “+Collections.max(myList));

our compareTomethod would be used as the basis for determining this behind the scenes

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

shuffle

A

randomly shuffle our list

Collections.shuffle(arrayList);

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