Set Flashcards

1
Q

What is a set

A

set in Java is an unordered collection of elements that cannot contain duplicate values.

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

Mention methods in Set interface

A

add(E element): Adds the specified element to the set if it is not already present.

remove(Object o): Removes the specified element from the set if it is present.

contains(Object o): Returns true if the set contains the specified element.

size(): Returns the number of elements in the set.

isEmpty(): Returns true if the set contains no elements.

clear(): Removes all elements from the set.

iterator(): Returns an iterator over the elements in the set.

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

Definition of hash set

A

HashSet: Use when you need a fast, unordered set and the order of elements is not important.

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

Definition of linked hash set

A

LinkedHashSet: Use when you need to maintain the order of insertion, and you also want fast access times.

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

Definition of Tree set

A

TreeSet: Use when you need elements to be sorted and require additional navigational methods, such as finding the smallest or largest element.

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