Last active
August 29, 2015 13:56
-
-
Save jeevan-patil/9018662 to your computer and use it in GitHub Desktop.
Demonstrate how to add elements to Set.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.java.collections; | |
import java.util.HashSet; | |
import java.util.Set; | |
/** | |
* | |
* @author jeevan | |
* @date 15-Feb-2014 | |
* @purpose Demonstrate how to add elements to Set. | |
* | |
*/ | |
public class SetImpl { | |
public static void main(String[] a) { | |
Set<String> set = new HashSet<String>(); | |
set.add("a"); | |
set.add("b"); | |
set.add("c"); | |
set.add("d"); | |
set.add("a"); | |
set.add("c"); | |
System.out.println(set.add("e")); | |
System.out.println(set.add("a")); | |
System.out.println("Elements in set are: " + set); | |
} | |
} | |
/** | |
true | |
false | |
Elements in set are: [d, e, b, c, a] | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment