Collection Flashcards

1
Q

Collection

A

-interface implemented by all collections

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

Collections

A

-class with static methods used to manipulate collections

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

Ordering

A
  • how an element is stored

- determines where an element is in a collection.For example, a List stores elements with an index, like an array.

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

Sorting

A

-determines an elements position based on the elements value.For example, a SortedSet maintains order by comparisons made according to a supplied rule.Your sorting rule might be alphabetical order, or age, or some other system you define.

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

HashSet

A
  • Unsorted

- no duplicates

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

TreeSet

A
  • Sorted

- no duplicates

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

When to used collections?

A

For instance, if you needed a container that had only unique elements then a Set would be your preferred choice.If you don’t require all elements to be unique then a List might be better.A Map is great for managing associations between information such as keeping a username associated with an id.If order matters in your collection, typically you would use a sorted version of your container such as a TreeMap or TreeSet.But If speed is more important, you would use the unsorted version such as HashMap or HashSet.

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

Maps

A
  • Map interface does not extend the collection interface
  • stores data in key-value pairs
  • sometimes called “Dictionaries”
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Map Implementations

A
  • HashTable and HashMap use hash codes to uniquely identify contents
  • hashing functions are complicated equations defined in Object.hashCode()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Differences between HashTable and HashMap

A

-One of the most important differences between Hashtable and HashMap, is that Hashtable is synchronized - meaning that in applications that use multiple concurrent processes or threads, a Hashtable can be accessed safely by two different processes at the same time.HashMap is not synchronized, but it is faster and preferred for applications where only one process needs to access the map at a time.Also, a Hashtable does not allow any null keys or values whereas a HashMap will allow up to one null key and any value can be null

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

TreeMap

A

similar to hash map but its elements are sorted

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

Map Methods

A
-maps can access contents in O(1).
put
get
remove
keySet
Values
How well did you know this?
1
Not at all
2
3
4
5
Perfectly