3:06 pm - Friday September 26, 2724

Clear elements from Hashset using void clear()

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

BACK

This tutorial explains how  to Clear elements from Hashset using void clear() method.

Removes all of the elements from this set. The set will be empty after this call returns.

 The hashset contains data only the clear function works.

Example

import java.util.HashSet;
public class ClearElements

{
  public static void main(String a[])
  {
        HashSet<Integer> hs = new HashSet<Integer>();        

        hs.add(12);

        hs.add(23);

        hs.add(5);

        hs.add(6);

        hs.add(6);

        hs.add(6);

        System.out.println(hs);

        hs.clear();

        System.out.println(hs);       
    }
}

Output

          [5, 6, 23, 12]

                  []

BACK

Filed in: Java Examples

Comments are closed.