3:42 pm - Thursday November 18, 9943

The program using Hash 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</strong>

//*@descriptions : This program explain the function and use of add() method
import java.util.HashSet;

class Collections {

public static void main(String[] args) {

//creating HashSet Object

HashSet hSet = new HashSet();

//add() method is used to insert the elements ito the set

hSet.add(new Integer("1"));

hSet.add(new Integer("2"));

hSet.add(new Integer("3"));

System.out.println("HashSet contains.." + hSet);

}

}

Output:

D:\CandidJava\Util\HashSet>javac Collections.java

Note: Collections.java uses unchecked or unsafe operations.

Note: Recompile with -Xlint:unchecked for details.

D:\CandidJava\Util\HashSet>java Collections

HashSet contains..[1, 2, 3]

Filed in: Z-A All Java Codes

No comments yet.

Leave a Reply