4:59 am - Wednesday September 26, 2018

LinkedHashSet example program to empty the elements from the set

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044
/**
 *@author :CandidJava.com
 *@descriptions : This program explain the function and use of clear() method
 */
import java.util.*;

class LinkedHashSetAdd {
	public static void main(String args[]) {
		// creating LinkedHashMap Object
		LinkedHashSet LHSet = new LinkedHashSet();
		LHSet.add("C");
		LHSet.add("A");
		LHSet.add("B");
		LHSet.add("E");
		LHSet.add("F");
		LHSet.add("D");
		// clear() method is used to remove all the values from the Set
		LHSet.clear();
		System.out.println("The LHSet elements are: " + LHSet);
	}
}

output:

D:\CandidJava\Util\LinkedHashSet>javac LinkedHashSetAdd.java

Note: LinkedHashSetDemo.java uses unchecked or unsafe operations.

Note: Recompile with -Xlint:unchecked for details.

D:\CandidJava\Util\LinkedHashSet>java LinkedHashSetAdd

The LHSet elements are: [] */

BACK

Filed in: Z-A All Java Codes

No comments yet.

Leave a Reply