Difference between revisions of "Set"
(Created page with "==EnumSet== ==HashSet== ==LinkedHashSet== ==TreeSet==") |
|||
| Line 1: | Line 1: | ||
| + | The java.util.Set interface is a subtype of the java.util.Collection interface. It represents set of objects, meaning each element can only exists once in a Set. | ||
| + | |||
| + | '''Java Set Example''' | ||
| + | |||
| + | <syntaxhighlight lang="java"> | ||
| + | Set setA = new HashSet(); | ||
| + | |||
| + | String element = "element 1"; | ||
| + | |||
| + | setA.add(element); | ||
| + | |||
| + | System.out.println( setA.contains(element) ); | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | |||
==[[EnumSet]]== | ==[[EnumSet]]== | ||
==[[HashSet]]== | ==[[HashSet]]== | ||
==[[LinkedHashSet]]== | ==[[LinkedHashSet]]== | ||
==[[TreeSet]]== | ==[[TreeSet]]== | ||
Revision as of 10:43, 3 July 2018
The java.util.Set interface is a subtype of the java.util.Collection interface. It represents set of objects, meaning each element can only exists once in a Set.
Java Set Example
Set setA = new HashSet();
String element = "element 1";
setA.add(element);
System.out.println( setA.contains(element) );