- 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
Karthikeya Boyini has Published 2383 Articles
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
karthikeya Boyini
276 Views
To remove all the elements from LinkedHashSet in Java, use the clear() method.The following is an example to declare LinkedHashSet and add elements to it −LinkedHashSet hashSet = new LinkedHashSet(); hashSet.add(10); hashSet.add(20); hashSet.add(30); hashSet.add(40); hashSet.add(50); hashSet.add(60);Use the clear() method to remove all elements −hashSet.clear();The following is an example −Example Live Demoimport ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
karthikeya Boyini
134 Views
To display the last entry from NavigableMap in Java, use the lastEntry() method.Let us first create NavigableMap.NavigableMap n = new TreeMap(); n.put("A", 498); n.put("B", 389); n.put("C", 868); n.put("D", 988); n.put("E", 686); n.put("F", 888); n.put("G", 999); n.put("H", 444); n.put("I", 555); n.put("J", 666);Get the last entry now.n.lastEntry()The following is an example to ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
karthikeya Boyini
407 Views
Use the containsKey() method to check whether a particular key exists in LinkedHashMap or not.Create a LinkedHashMap −LinkedHashMap l = new LinkedHashMap(); l.put(1, "Mars"); l.put(2, "Earth"); l.put(3, "Jupiter"); l.put(4, "Saturn"); l.put(5, "Venus");Now, let’s say we need to check whether key 4 exists or not. For that, use the containsKey() method ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
karthikeya Boyini
212 Views
Elements can be filled in a Java double array in a specified range using the java.util.Arrays.fill() method. This method assigns the required double value in the specified range to the double array in Java.The parameters required for the Arrays.fill() method are the array name, the index of the first element ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
karthikeya Boyini
82 Views
The headset() method returns elements up to a limit defined as a parameter.First, create a NavigableSet and add elements −NavigableSet set = new TreeSet(); set.add(10); set.add(25); set.add(40); set.add(55); set.add(70); set.add(85); set.add(100);Now, use the headset() method −set.headSet(55));The following is an example −Example Live Demoimport java.util.NavigableSet; import java.util.TreeSet; public class Demo { ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
karthikeya Boyini
124 Views
First, create a LinkedHashSet and add elements −LinkedHashSet l = new LinkedHashSet(); l.add(new String("1")); l.add(new String("2")); l.add(new String("3")); l.add(new String("4")); l.add(new String("5")); l.add(new String("6")); l.add(new String("7"));Now, copy it to an object array like this −// copying Object[] arr = l.toArray();The following is an example to copy all elements of a ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
karthikeya Boyini
278 Views
An ArrayList can be created from another collection using the java.util.Arrays.asList() method. A program that demonstrates this is given as follows −Example Live Demoimport java.util.ArrayList; import java.util.Arrays; import java.util.List; public class Demo { public static void main(String args[]) throws Exception { String str[] = { "John", "Macy", ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
karthikeya Boyini
103 Views
Elements can be filled in a Java long array in a specified range using the java.util.Arrays.fill() method. This method assigns the required long value in the specified range to the long array in Java.The parameters required for the Arrays.fill() method are the array name, the index of the first element ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
karthikeya Boyini
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.*; ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
karthikeya Boyini
465 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 { ... Read More