-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathLinkedHashSetTest.java
44 lines (35 loc) · 1.07 KB
/
LinkedHashSetTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//A linked hash set is similar to a tree set except that it is faster in certain operations.
//There are 3 hash sets: linked hash set, regular hash set, tree hash set
//package tutorial;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;
public class LinkedHashSetTest
{
//main method
public static void main (String[] args)
{
//Syntax: Set<Datatype> nameofSet = new TreeSet<datatype>()
Set<Integer> t = new LinkedHashSet<Integer>();
//To append to a Set
t.add(5);
t.add(8);
t.add(5);
t.add(9);
System.out.println(t);//prints 5, 8, 9
t.add(-8);
t.remove(8);
//clear an entire Set
//t.clear();
//check if empty
//t.isEmpty()
//get the length of the Set
//t.size();
//Check if element exists within the Set
boolean m = t.contains(5);
System.out.println(m);
System.out.println(t);
}
}