

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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
<p>Use the subset() method to get elements from a limit. At first, create NavigableSet and add elements −</p><pre class="result notranslate">NavigableSet<Integer> set = new TreeSet<>(); set.add(10); set.add(25); set.add(40); set.add(55); set.add(70); set.add(85);</pre><p>Now, use the subset() method −</p><pre class="result notranslate">set.subSet(40, 85)</pre><p>The following is an example to implement subset() method of Java NaviagbleSet class −</p><h2>Example</h2><p><a class="demo" href="http://tpcg.io/DOP9iS" rel="nofollow" target="_blank"> Live Demo</a></p><pre class="prettyprint notranslate">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)); } }</pre><h2>Output</h2><pre class="result notranslate">Returned Value = [40, 55, 70]</pre>
- Related Questions & Answers
- How to use headSet() method of Java NavigableSet Class
- NavigableSet Class ceiling() method in Java
- NavigableSet Class floor() method in Java
- NavigableSet Class higher() method in Java
- NavigableSet Class lower() 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 ReadKey() method of Console class in C#?
- How to use WriteLine() method of Console class in C#?
- Java Program to get the reverse of the NavigableSet
- How to use jQuery.closest() method with class selector?
- How to use the Clear method of array class in C#?
- How to use the Clone() method of array class in C#?
- How to use the Copy(, ,) method of array class in C#
- How to use the CopyTo(,) method of array class in C#
Advertisements