-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjavaGenericsSet12.java
36 lines (29 loc) · 1018 Bytes
/
javaGenericsSet12.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
import java.util.HashSet;
import java.util.Scanner;
public class javaGenericsSet12<T> {
static Scanner sc;
HashSet<T> set = new HashSet<>();
T[] data;
javaGenericsSet12(int capacity) {
data = (T[]) new Integer[capacity];
}
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);
System.out.println("Enter the capacity of the array:");
int capacity = sc.nextInt();
javaGenericsSet12<Integer> setDemo = new javaGenericsSet12<>(capacity);
for (int i = 0; i < setDemo.data.length; i++) {
System.out.println("index:" + i + " value:");
setDemo.data[i] = sc.nextInt();
}
setDemo.gen(setDemo.set, setDemo.data);
System.out.println(setDemo.set);
}
}