September 27, 2008 at 12:02 PM
Hi friend,
A set is a collection interface. It is connot contain any dublicate element. The Set and SortedSet intefaces describe the properties of sets and the HashSet, LinkedHashSet, and TreeSet classes implement these interfaces.
Here is the simple code.
import java.util.*;
public class HashSetDemo {
static final int MIN = 1;
static final int MAX = 10;
public static void main(String args[]) {
Set<Integer> sethash = new HashSet<Integer>();
for (int i = MAX; i >= MIN; i--) {
sethash.add(new Integer(i*i));
}
System.out.println("HashSet = " + sethash);
Set<Integer> setlink = new LinkedHashSet<Integer>();
for (int i = MAX; i >= MIN; i--) {
setlink.add(new Integer(i*i));
}
System.out.println("LinkedHashSet = " + setlink);
Set<Integer> settree = new TreeSet<Integer>();
for (int i = MAX; i >= MIN; i--) {
settree.add(new Integer(i*i));
}
System.out.println("TreeSet = " + settree);
}
}
----------------------------------
Visit for more information.
http://www.roseindia.net/java/example/java/util/Thanks.
Amardeep
Related Tutorials/Questions & Answers:
program for HashSet - Java Beginnersprogram for HashSet I need a
program that illustratest the concept of
HashSet. can u please suggest me a way out. Hi friend,
A set... and SortedSet intefaces describe the properties of sets and the
HashSet Advertisements
Example of HashSet class in javaExample of
HashSet class in java.
In this part of tutorial, we will introduce you to about the
HashSet class.
It is collection. It stores only unique. You can not store duplicate value.
Java
hashset example.
How
Java HashSet - Java TutorialsJava Collections Framework-
HashSet Class
A
HashSet is a collection set.... This class permits
the null element.
The
HashSet class supports four...
HashSet( )
HashSet(Collection c)
HashSet(int capacity)
HashSet(int
Java hashset example.Java
hashset example.
HashSet is a collection. You can not store duplicate value in
HashSet.
In this java
hashset exmple, you will see how to create
HashSet in java
application and how to store value in
Hashset Java collection HashSetJava collection HashSet How can we use
HashSet in java
program?
The
hashSet class is used to create a collection and store... set = new
HashSet();
boolean[] flags = new boolean[10];
flags[0
Collection : HashSet ExampleCollection :
HashSet Example
This tutorial contains description of
HashSet with example.
HashSet :
HashSet class extends AbstractSet class... time. It does not allow
duplicate value.
HashSet does not provide any its own
HASHSET - Java Interview QuestionsHASHSET How To Sort
HashSet?I Want Source Code?
Hi Friend,
Try the following code:
import java.util.*;
public class HashSetExample{
public static void main (String args[]){
Set set = new
HashSet HashMap/HashSet - Java BeginnersHashMap/HashSet im working on a game, and i want to know how does the code for HashMap and
HashSet work or can you give me the code that needs to be included in the game engine.
I have the exam on monday. Can you please help
Java HashSet Collection problemJava
HashSet Collection problem Here's how the
HashSet works... the concept behind this??
In your code,
HashSet stores the values...;Prac>();
So, while adding the object of Prac using add method of
hashset, it get
Example of Hashset size() method in java.
Example of
Hashset size() method in java.
The size() is a method of
HashSet class. It is used to calculte the size of
HashSet. The size of method is equal to total number of elements in
HashSet
Code:
Java collection HashSet and TreeSet Java collection
HashSet and TreeSet How can we used
HashSet... two subclasses
HashSet and TreeSet. Now using the add() method, we have added elements to
HashSet. Set does not accept duplicate values. So here we have checked
Example of contains method of hashset in java.
Example of contains method of
hashset in java.
The contains() is a method of
hashset. It is used for checking that the
given number is available in
hashset or not. It returns only boolean value.If number is present in
hashset What is HashSet in javaIn following example we will discuss about
HashSet in Java. The
HashSet class... for
HashSet
method.hashSet stored only object
HashSet class in java.util package. The
HashSet does not
accept duplicate value.
HashSet has many available methods like
HashSet Example the
HashSet is empty, our
program checks for it and displays a
message "... of
HashSet.
Here is the code of
program:
ADS_TO_REPLACE_2...
HashSet Example
Example of Hashset iterator method in java.Example of
Hashset iterator method in java.
In this exmple of
HashSet class... element from
HashSet.
Code:
HashSetRemoveElement.java
package... || []).push({});
HashSet obHashSet = new
HashSet();
obHashSet.add(new
HashSet In JavaHashSet In Java
In this section we will read about
HashSet in Java.
HashSet... the Set interface. This class is supported by the instance of HashMap.
HashSet allows to insert the null element.
HashSet is not thread safe i.e. in
multiple
Example of toArray() method of hashset in java.
Example of toArray() method of
hashset in java.
The toArray() is a method of
HashSet in java. It is used to create array
of object. It is also used to copy all element of
hashset into array of object.
Code:
How to remove all element from Hashset.How to remove all element from
Hashset.
HashSet is set type Collection...; it .In this example, you will see the use of clear method of
HashSet. It is used
to remove all element of
hashset.
Code:
HashSetRemoveElement.java
How to remove specific element from Hashset.How to remove specific element from
Hashset.
In this exmple, you will see
how to remove specific element from
hashset.
The
HashSet class provides...) {
(adsbygoogle = window.adsbygoogle || []).push({});
HashSet obHashSet
programprogram any
program of hotel or school management
programprogram
program of jdbc using ms access for creating table
programprogram write a javascript
program to create a application form with validation
programprogram write a html
program in show table and this word
in box
programprogram write a
program different between to dates in terms of days in java
programprogram WAP a java
program to form 1/2+3/4+5/6+7/8 series
programprogram Write a
program to find the difference between sum of the squares and the square of the sums of n numbers
programprogram write a
program reversee a string.
input-hi this is roseindia
output-roseindia is this hi
programprogram develop a servlet to insert the data in the database from our
program in the table stored in the database
programprogram An old-style movie theater has a simple profit
program. Each customer pays $5 per ticket. Every performance costs the theater $20, plus $.50 per attendee. Develop the
program calculateTotalProfit that consumes
programprogram write a java
program to input a no. and print wheather the no. is a special no or not. (special no. are those no whose factorial of the sum of digit of the no is same as the original
programprogram Develop the
program calculateCylinderArea, which accepts radius of the cylinder's base disk and its height and computes surface area of the cylinder
programprogram explanation of
program on extending thread class
Hi Friend,
Please go through the following link:ADS_TO_REPLACE_1
Java Threads
Thanks
programprogram Develop a
program that computes the distance a boat travels across a river, given the width of the river, the boat's speed perpendicular to the river, and the river's speed. Speed is distance/time, and the Pythagorean
programprogram how to improve programming skills plss tell some tips..i am understanding concepts but unable to write
program so,pls give some guideness plsss
ProgramProgram a
program to prove that default constructor of super class is available to subclass by default. Define a parameterize constructor for super class to store name = â??Tommyâ?? age=â??23â?? and call this constructor
ProgramProgram a
program to create two classes Commercial and Domestic. Override the method calculatebill() of Commercial class(Rs.8 per unit) into Domestic class(Rs 6 per unit) to compute electricity bill for both classes
programprogram no i want a
program that shows how merge sort algorithm works in graphical representations like numbers are taken in circles and computation... in rectangles or circles wat ever it may be. the theme of
program is to show algorithm
programprogram . Develop a
program that accepts an initial amount of money (called the principal), a simple annual interest rate, and a number of months will compute the balance at the end of that time. Assume that no additional
programprogram Write a JSP
Program, which displays a web page containing the name of the Courses, Courses being offered currently, number of students enrolled in each course, new courses to be offered, eligibility criteria for taking
programprogram i want a progra in java to print a sentence in alphabetic order, taking the input from the user.the
program should writen without using the array
for example : if input= this is a cat
then output sould = a cat
programprogram Utopias tax accountants always use programs that compute income taxes even though the tax rate is a solid, never-changing 15%. Define the
program calculateTax which determines the tax on the gross pay. Define
programprogram Write a JSP
Program, which displays a web page containing two web links one for your profiling and other for the schedule of theory of practical classes of your Batch. When one click on link for getting your profile
programprogram Write a
program to print details of a week for a particular day using array of objects Integer and String.
OUTPUT:
First Day of Week is Monday
Second Day of Week is Tuesday
Third Day of Week is Wednesday
Forth Day
SCJP Module-9 Question-1
The '
HashSet' doesn't allow to store duplicate collections. That's why 'Buzz'
is stored once in
HashSet 'hs'
program for Hashmaps - Java Beginnersprogram for Hashmaps I need a
program that illustrates the concept of HashMaps.please can you suggest me a way out. Hi,
A
HashSet is implemented with a backing HashMap structure. In other words, a
HashSet uses