Skip to content

Instantly share code, notes, and snippets.

@jeevan-patil
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeevan-patil/9018662 to your computer and use it in GitHub Desktop.
Save jeevan-patil/9018662 to your computer and use it in GitHub Desktop.
Demonstrate how to add elements to Set.
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