- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
Found 4336 Articles for Java 8
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
152 Views
To get the Tail Set from TreeSet, use the tailSet() method. Tail Set begins from a point and returns the elements greater than the element set in the beginning.First, create a TreeSet and add elements −TreeSet set = new TreeSet(); set.add("78"); set.add("56"); set.add("88"); set.add("54"); set.add("76"); set.add("34");Now, get the Tail Set −SortedSet sorted = set.tailSet("56");The following is an example to get Tail Set from TreeSet −Example Live Demoimport java.util.*; public class Demo { public static void main(String args[]){ TreeSet set = new TreeSet(); set.add("78"); set.add("56"); set.add("88"); ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
702 Views
Two ArrayList can be compared to check if they are equal or not using the method java.util.ArrayList.equals(). This method has a single parameter i.e. an ArrayList that is compared with the current object. It returns true if the two ArrayList are equal and false otherwise.A program that demonstrates this is given as follows −Example Live Demoimport java.util.ArrayList; import java.util.List; public class Demo { public static void main(String[] args) { List aList1 = new ArrayList(); aList1.add("Sun"); aList1.add("Moon"); ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
77 Views
Clear the IdentityHashMap using the clear() method.Create an IdentityHashMap and add elements to it −Map m = new IdentityHashMap(); m.put("1", 100); m.put("2", 200); m.put("3", 300); m.put("4", 150); m.put("5", 110); m.put("6", 50); m.put("7", 90); m.put("8", 250);Now, let us use the clear() method to remove all the elements −m.clear()The following is an example to remove all elements in IdentityHashMap in Java −Example Live Demoimport java.util.*; public class Demo { public static void main(String[] args) { Map m = new IdentityHashMap(); m.put("1", 100); ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
148 Views
To get the sub set from TreeSet, use the subSet() method. Let us first create a TreeSet and add elements to it −TreeSet set = new TreeSet(); set.add("78"); set.add("56"); set.add("88"); set.add("54"); set.add("76"); set.add("34");Let us get the subset now from a range of elements −SortedSet sorted = set.subSet("54", "76");The following is an example to get sub set from Java TreeSet −Example Live Demoimport java.util.*; public class Demo { public static void main(String args[]){ TreeSet set = new TreeSet(); set.add("78"); set.add("56"); ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
396 Views
To get the size of TreeSet, use the size() method.Create a TreeSet and add elements to it −TreeSet tSet = new TreeSet(); tSet.add("78"); tSet.add("56"); tSet.add("88"); tSet.add("12");Now, get the size of the TreeSet −tSet.size()The following is an example to get the size of TreeSet in Java −Example Live Demoimport java.util.*; public class Demo { public static void main(String args[]){ TreeSet tSet = new TreeSet(); tSet.add("78"); tSet.add("56"); tSet.add("88"); tSet.add("12"); ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
362 Views
To remove the highest element, use the pollLast() method.Create a TreeSet and add elements to it −TreeSet tSet = new TreeSet(); tSet.add("78"); tSet.add("56"); tSet.add("88"); tSet.add("12");Now, remove the highest element −tSet.pollLast()The following is an example to remove highest element in Java TreeSet −Example Live Demoimport java.util.*; public class Demo { public static void main(String args[]){ TreeSet tSet = new TreeSet(); tSet.add("78"); tSet.add("56"); tSet.add("88"); tSet.add("12"); ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
468 Views
To remove the lowest element, use the pollFirst() method.Create a TreeSet and add elements to it −TreeSet tSet = new TreeSet(); tSet.add("78"); tSet.add("56"); tSet.add("88"); tSet.add("12");Now, remove the lowest element −tSet.pollFirst()The following is an example to remove lowest element in Java TreeSet −Example Live Demoimport java.util.*; public class Demo { public static void main(String args[]){ TreeSet tSet = new TreeSet(); tSet.add("78"); tSet.add("56"); tSet.add("88"); tSet.add("12"); ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
513 Views
To get the last value in TreeSet, use the last() method.First, get the TreeSet and add elements to it −TreeSet tSet = new TreeSet(); tSet.add("10"); tSet.add("20"); tSet.add("30"); tSet.add("40"); tSet.add("50"); tSet.add("60");Now, get the first value −tSet.last()The following is an example to get the last value in TreeSet −Example Live Demoimport java.util.*; public class Demo { public static void main(String args[]){ TreeSet tSet = new TreeSet(); tSet.add("10"); tSet.add("20"); tSet.add("30"); ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
227 Views
Create a TreeSet and add elements −TreeSet tSet = new TreeSet(); tSet.add("TV"); tSet.add("Radio"); tSet.add("Internet");Now, let us copy it to object array −Object[] arr = tSet.toArray(); for (Object ob: arr) { System.out.println(ob); }The following is an example to copy all elements in TreeSet to an Object Array −Example Live Demoimport java.util.*; public class Demo { public static void main(String args[]){ TreeSet tSet = new TreeSet(); tSet.add("TV"); tSet.add("Radio"); tSet.add("Internet"); System.out.println("TreeSet elements = "+tSet); ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
99 Views
Create a TreeSet and add elements −TreeSet tSet = new TreeSet(); tSet.add("TV"); tSet.add("Radio"); tSet.add("Internet");Iterate through the elements −Iterator i = tSet.iterator(); while(i.hasNext()){ System.out.println(i.next()); }The following is an example to create a TreeSet −Example Live Demoimport java.util.*; public class Demo { public static void main(String args[]){ TreeSet tSet = new TreeSet(); tSet.add("TV"); tSet.add("Radio"); tSet.add("Internet"); Iterator i = tSet.iterator(); while(i.hasNext()){ System.out.println(i.next()); } } }OutputInternet Radio TV