3:13 pm - Saturday December 16, 8400

Add elements to HashSet using boolean add(E e)

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 Add elements to HashSet using boolean add() method.

True if this set did not already contain the specified element.

 Duplicate element three did not add in the list more than once.

When you repeat the same element ,It only one among elements.

Example

import java.util.HashSet;
public class AddElement
public static void main(String a[])
{
        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>
}
}

Output

          [second, third, first]

BACK

Filed in: Java Examples

Comments are closed.