-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjavaGenericsSet11.java
More file actions
29 lines (25 loc) · 867 Bytes
/
Copy pathjavaGenericsSet11.java
File metadata and controls
29 lines (25 loc) · 867 Bytes
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
import java.util.HashSet;
import java.util.Scanner;
public class javaGenericsSet11<T> {
static Scanner sc;
HashSet<T> set = new HashSet<>();
T[]arr;
public void gen (HashSet<T> set ,T[] arr){
this.set = set;
for (int i = 0; i < arr.length; i++) {
set.add(arr[i]);
}
System.out.println(set);
}
public static void main(String[] args) {
sc = new Scanner(System.in);
javaGenericsSet11<Integer> setDemo1 = new javaGenericsSet11<>();
setDemo1.arr = new Integer[10];
for (int i = 0; i < setDemo1.arr.length; i++) {
System.out.println("index:" + i + " value:");
setDemo1.arr[i] = sc.nextInt();
}
setDemo1.gen(setDemo1.set, setDemo1.arr);
System.out.println(setDemo1.set);
}
}