3:53 pm - Saturday March 24, 2356

LinkedHashSet example program for add(),clear() and remove()

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 add(),clear() and remove() method
 */
import java.util.LinkedHashSet;

class LinkedHashSetClear {
	public static void main(String[] args) {
		// creating LinkedHashSet Object
		LinkedHashSet lhashSet = new LinkedHashSet();
		// add() method is used to insert the elements into the set
		lhashSet.add(new Integer("1"));
		lhashSet.add(new Integer("2"));
		lhashSet.add(new Integer("3"));
		// clear() method is used to remove all the values from the set
		lhashSet.clear();
		System.out.println("LinkedHashSet contains.." + lhashSet);
	}
}

output:

D:\CandidJava\Util\LinkedHashSetm>javac LinkedHashSetExample.java

Note: LinkedHashSetExample.java uses unchecked or unsafe operations.

Note: Recompile with -Xlint:unchecked for details.

D:\CandidJava\Util\LinkedHashSet>java LinkedHashSetExample

LinkedHashSet contains..[1, 2, 3] */

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

Note: LinkedHashSetExample.java uses unchecked or unsafe operations.

Note: Recompile with -Xlint:unchecked for details.

LinkedHashSetmgm>java LinkedHashSetExample

LinkedHashSet contains..[]

BACK

Filed in: Z-A All Java Codes

No comments yet.

Leave a Reply