Site icon Narayana Tutorial

Set

Set

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

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

  • The underlying data structure is HasSet.
  • Insertion order is not preserved.
  • Introduced in 1.2

 

  • The underlying data structure is a combination.
  • Insertion order is preserve.
  • Introduced in version (1.4)

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.