0% found this document useful (0 votes)
5 views7 pages

Revision Java

The document describes various data structures in Java, including Stack, Set, HashSet, LinkedHashSet, TreeSet, and PriorityQueue. A Stack follows the Last In, First Out (LIFO) principle, while Sets are collections that do not allow duplicates. The document details the characteristics of HashSet, LinkedHashSet, and TreeSet, as well as the functionality of PriorityQueue in maintaining sorted order.

Uploaded by

xdnik76
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views7 pages

Revision Java

The document describes various data structures in Java, including Stack, Set, HashSet, LinkedHashSet, TreeSet, and PriorityQueue. A Stack follows the Last In, First Out (LIFO) principle, while Sets are collections that do not allow duplicates. The document details the characteristics of HashSet, LinkedHashSet, and TreeSet, as well as the functionality of PriorityQueue in maintaining sorted order.

Uploaded by

xdnik76
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

7.

A Stack is a linear data structure where you can only add or remove items from the top. It
follows Last In, First Out (LIFO) rule — that is last item you put in the stack will be the first one
you take out.

8.

Set is a collection in Java that does not allow duplicate elements. It is a part of the Java
Collections Framework and is used when we want to store unique items only.

1. HashSet

✅ Definition:

 HashSet stores elements using a hash table.

 It does not maintain any order (neither insertion nor sorted).

 Allows null values (only one null element).

2. LinkedHashSet

✅ Definition:

 LinkedHashSet is similar to HashSet but maintains insertion order.

 Elements are stored in the order they were added.

 Useful when order matters and duplicates need to be avoided.

3. TreeSet

✅ Definition:

 TreeSet stores elements in sorted (natural) order.

 It does not allow null elements.

 Automatically maintains elements in ascending order.


13.

In Java, a PriorityQueue is a part of the java.util package and automatically maintains elements
in sorted order (natural order for numbers). Internally, it uses a min-heap to store elements.

By using PriorityQueue, we can insert a set of integers and retrieve them in ascending sorted
order by polling the elements one by one.

You might also like