Click here to watch in Youtube :https://www.youtube.com/watch?v=4kxUMyogbEY&list=UUhwKlOVR041tngjerWxVccwLinkedHashSetExample.java import java.util.LinkedHashSet;
/*
* Example of clear() method.
*/
public class LinkedHashSetExample
{
public static void main( String[] args )
{
LinkedHashSet<String> linkedHashSet = new LinkedHashSet<String>();
linkedHashSet.add("Dave");
linkedHashSet.add("Peter");
linkedHashSet.add("Phil");
linkedHashSet.add("Rohit");
linkedHashSet.add("Virat");
System.out.println("linkedHashSet: " + linkedHashSet + "\n");
/*
* Removes all of the elements from this set. The set will be empty
* after this call returns.
*/
linkedHashSet.clear();
System.out.println("linkedHashSet: " + linkedHashSet + "\n");
}
}
Output linkedHashSet: [Dave, Peter, Phil, Rohit, Virat]
linkedHashSet: []