This project provides examples of using TreeSet in Java with different scenarios.
The project demonstrates the usage of TreeSet and its various methods for storing and retrieving elements in sorted order. It includes examples of using TreeSet with built-in classes, user-defined classes implementing Comparable interface, and user-defined classes with a custom Comparator.
The project includes the following classes:
Person
: A user-defined class implementing theComparable
interface. It represents a person with a name and an ID.Student
: A user-defined class representing a student with a name and an ID.NameComparator
: A customComparator
implementation for sortingStudent
objects based on their names.TreeSetLearning
: The main class that demonstrates the usage of TreeSet and its methods.
To run the project:
- Clone the repository.
- Open the project in your preferred Java IDE.
- Run the
TreeSetLearning
class.
The project showcases the following features:
- Creating and adding elements to a TreeSet of built-in classes (
Integer
). - Using TreeSet methods such as
ceiling
,descendingSet
, anddescendingIterator
. - Creating and adding elements to a TreeSet of user-defined class (
Person
) that implements theComparable
interface. - Creating and adding elements to a TreeSet of user-defined class (
Student
) using a customComparator
(NameComparator
).
Contributions to this project are welcome! If you find any issues or have suggestions for improvements, please feel free to open an issue or submit a pull request.