-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSet_Linkedhashset.java
66 lines (36 loc) · 1.73 KB
/
Set_Linkedhashset.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package com.mywork;
import java.util.LinkedHashSet;
import java.util.Set;
public class Set_Linkedhashset {
public static void main(String[] args) {
Set<Integer> a = new LinkedHashSet<Integer>();
a.add(10);
a.add(20);// duplicate value cnnot ccept
a.add(50);
a.add(20);
a.add(50);
a.add(70);//method --add
System.out.println(a);
//a.add(2, 88);
//a.add(3, 15);
//System.out.println(a);//(method -- add(index,object)// cannot replace the value using add index
int size = a.size();//index of length
System.out.println("The value of index size = " + size); // (method ----size)
// int indexOf = a.indexOf(50);
//System.out.println("the value of index of =" + indexOf); //(it will print the first occurrence of the value)
//int lastIndexOf = a.lastIndexOf(50);
//System.out.println("The last index of =" + lastIndexOf);// (it will print the last occurrence of the value)
boolean contains = a.contains(70);
System.out.println("The given value in present or not in contains =" + contains);
// (it will check the value is present or not -- true or false)
//Integer integer = a.get(4);
//System.out.println("the value of get="+ integer);//it will get the value from index what we choose,if we declare unknown index value
//will through indexout of bounds exception
//a.set(3, 123);
//System.out.println(a);//it will replace the index value no return type
boolean empty = a.isEmpty();
System.out.println("the vlue of index is empty or not:" + empty);
a.clear();
System.out.println(a);//will clear the index box
}
}