- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to use subSet() method of Java NavigableSet Class
Use the subset() method to get elements from a limit. At first, create NavigableSet and add elements −
NavigableSet<Integer> set = new TreeSet<>(); set.add(10); set.add(25); set.add(40); set.add(55); set.add(70); set.add(85);
Now, use the subset() method −
set.subSet(40, 85)
The following is an example to implement subset() method of Java NaviagbleSet class −
Example
import java.util.NavigableSet; import java.util.TreeSet; public class Demo { public static void main(String[] args) { NavigableSet<Integer> set = new TreeSet<>(); set.add(10); set.add(25); set.add(40); set.add(55); set.add(70); set.add(85); set.add(100); System.out.println("Returned Value = " + set.subSet(40, 85)); } }
Output
Returned Value = [40, 55, 70]
- Related Articles
- How to use headSet() method of Java NavigableSet Class
- NavigableSet Class floor() method in Java
- NavigableSet Class higher() method in Java
- NavigableSet Class lower() method in Java
- NavigableSet Class ceiling() method in Java
- How to use isAlive() method of Thread class in Java?
- How to use the substring() method of java.lang.String class in Java?
- How to use WriteLine() method of Console class in C#?
- How to use ReadKey() method of Console class in C#?
- How to use jQuery.closest() method with class selector?
- How to use file class in Java?
- Java Program to get the reverse of the NavigableSet
- When can we use intern() method of String class in Java?
- How to use the Clear method of array class in C#?
- How to use the Clone() method of array class in C#?

Advertisements