7:26 pm - Thursday August 17, 2017

Remove elements from Hashset using boolean remove(Object o)

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 Remove elements from Hashset using  boolean remove(Object o) method.

True if the set contained the specified element

To remove the particular element in the hashset using hashset variable.remove()

Example

import java.util.HashSet;
public class AddDuplicate
{
 public static void main(String a[])</p>
{
       HashSet&lt;String&gt; hs = new HashSet&lt;String&gt;();</p>
        hs.add("first");</p>
        hs.add("second");</p>
        hs.add("third");</p>
        hs.add("third");</p>
        hs.add("third");</p>
        System.out.println(hs);</p>
        hs.remove("third");</p>

        System.out.println(hs);</p>
     }
}

Output

        [second, third, first]

        [second, first]

BACK

Filed in: Java Examples

Comments are closed.