This Java Example shows how to remove all elements exists in Linked HashSet.
clear in Java LinkedHashSet Example
This Java Example shows how to remove all elements exists in Linked HashSet. To remove all the elements exists in Linked HashSet We use clear() method of Linked HashSet class. It removes all the elements stored in the specified object within the collection. To check that specified Linked HashSet object is empty or not we use boolean isEmpty() method of the Linked HashSet class. This method returns true if the object is empty otherwise returns false.
Example:- RemoveAllInLinkedHashSet.java
package devmanuals.com; import java.util.*; public class RemoveAllInLinkedHashSet { public static void main(String args[]) { LinkedHashSet LHSet = new LinkedHashSet(); LHSet.add("C"); LHSet.add("A"); LHSet.add("B"); LHSet.add("E"); LHSet.add("F"); LHSet.add("D"); System.out.println("The LinkedHashSet elements are: " + LHSet); LHSet.clear(); boolean b1 = LHSet.isEmpty(); System.out.println("The LinkedHashSet is Empty : " + b1); System.out.println("The Elements are: " + LHSet); } }
Output:-
The LinkedHashSet elements are: [C, A, B, E, F, D]
The LinkedHashSet is Empty : true The Elements are: [] |
[ 0 ] Comments