Set
Table of Contents
It is the child interface of collection. If insertion order is not required & duplicate objects are not allowed. Then we should go for set interface. Set interface doesn’t contain any new method, hence we have to use only collection interface method.
* image *
Constructor
- HasSet h = new HasSet () // creates an empty HasSet object with default initial capacity 16 & default fill ration load factory is 0.75.
- HasSet h = new HasSet ( int initial capacity);
- HasSet h = new HasSet ( int initial capacity, float fill ratio // 0 to 1);
- HasSet h = new HasSet ( collection c)
Load Factor or Fill Ratio:-
import java. util. * ; Class ExonHasSet { public static void main ( String[] args ) { HasSet h = new HasSet (); h. add ("B" ); h. add ("C" ); h. add ("2" ); h. add (null); h. add (10); h. add (K); s.o.p ( h.add ( "Z" )); // false s.o.p ( h ); // ( in random order elements will be displayed Z,D,K, null,l,C,B,10) } }
Linked HasSet
It is child class of HasSet. It is exactly same as HasSet, except the following differences.
HasSet |
Linked HasSet |
|
|
In the above pregame, if we are replacing HasSet with LinkedHasSet is the ( B C Z Null 10 K ), inserting order is preserve. LinkedHasSet & LinkedHasMaps are best suitable to implement cache applications.
Hello! I am Narayanaswamy founder and admin of narayanatutorial.com. I have been working in the IT industry for more than 12 years. NarayanaTutorial is my web technologies blog. My specialties are Java / J2EE, Spring, Hibernate, Struts, Webservices, PHP, Oracle, MySQL, SQLServer, Web Hosting, Website Development, and IAM(ForgeRock) Specialist
I am a self-learner and passionate about training and writing. I am always trying my best to share my knowledge through my blog.