Shared Flashcard Set

Details

Java Collection Qs
n/a
20
Computer Science
Undergraduate 1
06/20/2013

Additional Computer Science Flashcards

 


 

Cards

Term
What is a Collection?
Definition
The root interface in the collection hierarchy, it represents a group of objects.
Term
What is a List?
Definition
It is an ordered collection (a sequence). The user has precise control over where each element is inserted.
Term
What is a Set?
Definition
A collection that contains no duplicate elements.
Term
What is a Map?
Definition
An object that maps keys to values. It cannot contain duplicate keys, and each key can map to at most one value.
Term
What is the difference between a HashMap and HashTable?
Definition
HashTable is synchronized and HashMap is not.
Term
What is an ArrayList?
Definition
Resizable-array implementation of the List interface. It is not synchronized.
Term
What is a Vector?
Definition
It implements a growable array of objects. It can grow and shrink as needed to accomodate the adding and removing items after the Vector has been implemented.
Term
Which collection does not allow duplicates?
Definition
Set
Term
What is the difference between Vector and ArrayList?
Definition
Vectors are synchronized, ArrayLists are not.
Term
What is the advantage of an ArrayList and a HashTable?
Definition

- ArrayList is an array, except it dynamically expands and contracts when elements are added/removed.

- HashTable is good when you want to lookup objects indexed by a 'key' value.

Term
How would you code a For loop to read through a HashMap?
Definition

You would use a ForEach loop, with the first param being the key, and the second being the obj's keySet().

example:

for(String key : temp.keySet()) { }

Term
What is the difference between HashTable, HashSet, and HashMap?
Definition

- HashTable maps keys to values, and any non-null obj can be a key or value.

- HashMap is like HashTable, but is unsynchronized and permits nulls.

- HashSet implements the Set interface, backed by a HashTable.

Term
What is hashing?
Definition
It means that some function or algorithm is used to map object data to some representative integer value. It helps narrows a search.
Term
What are the two kinds of Maps that Java has?
Definition
HashMap & TreeMap.
Term
What is a HashMap?
Definition

Implements the Map interface, it is roughly the same as Hashtable except that it is unsynchronized and permits nulls.

HashMap<K,V>

Term
What is HashTable?
Definition

Maps keys to values, does not permit nulls.

Hashtable<K,V>

Term
What is HashSet?
Definition

Implements the Set interface, there are no guarentees to the iteration order, nor does it promise consistency of the order over time. Permits null elements.

HashSet<E>

Term
What is a TreeMap?
Definition

Implements the Map interface, it sorts according to the natural ordering of its keys, or by a comparator provided at creation time.

TreeMap<K,V>

Term
How is a LinkedList different from a ArrayList?
Definition

- LinkedList: each element is linked to its previous element and next element.

- ArrayList: is an array-like list.

Term
What is a LinkedList?
Definition
Implements the List interface, each element is linked to the previous and next element making it easier to delete or insert in the middle of the list.
Supporting users have an ad free experience!