A Java program demonstrating various operations on TreeSet, including sorting, searching, statistics, and manipulation using different data sources.
- Default Ordering TreeSet: Stores elements in ascending order.
- Comparator-based TreeSet: Stores elements in descending order using a custom comparator.
- TreeSet from User Input: Allows users to enter values via the keyboard.
- Randomized TreeSet: Generates random values and stores them.
- TreeSet from an Array: Converts an array into a
TreeSetto remove duplicates. - TreeSet from a File: Reads values from
input.txtand stores them. - Search Operations: Allows searching for elements in the TreeSet.
- Deletion Operations: Enables removing elements from the TreeSet.
- Statistics on TreeSet: Provides insights such as the smallest/largest elements and subsets.
- Conversion to Array: Transforms
TreeSetinto an array. - Clearing Elements: Removes all elements from the TreeSet.
- Java Development Kit (JDK) installed
- An
input.txtfile (if using file-based input)
- Clone this repository:
git clone https://github.com/ShouNLAK/Learning_TreeSet.git
- Compile the Java program:
javac Learning_TreeSet.java
- Run the program:
java Learning_TreeSet
TreeSet [1, 3, 4, 5, 8]
TreeSet with Comparator [8, 5, 4, 3, 1]
Number of elements:
Please input value of the elements #1: 23
TreeSet from keyboard input: [23]
Elements #1 randomized: 67
TreeSet from Random: [67]
...- ShouNLAK
- Open to contributions! Feel free to fork, submit PRs, or suggest improvements.
This project is open-source. Feel free to use and modify it as needed.