Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • HashSet Class

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 419
    Comment on it

    HashSet Class:

    It extends AbstractList class and implements List interface. It uses hashing technique to store data. It contains only unique elements. We can use HashSet class by importing java.util package.


    import java.util.*;
    public class HashDemo {
       public static void main(String args[]) {
          // create a hash set 
          HashSet hash = new HashSet();
          // add elements to the hash set using add() function
          System.out.println(hash); //printing the hash collection


    [A, B, C, D, E, F]

    List can have duplicate elements but Set contains unique elements only.

    Some of the mostly used methods of HashSet :

    add(): used to add a element to the set

    clear(): Removes all element from the set.

    remove() :Removes the specified element from the set if it is present.

 0 Comment(s)

Sign In

Sign up using

Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: