We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent b8fce65 commit 965f8c9Copy full SHA for 965f8c9
1 file changed
generics/GenericMethodEx.java
@@ -0,0 +1,33 @@
1
+package com.zetcode;
2
+
3
+import java.util.HashSet;
4
+import java.util.Set;
5
6
+public class GenericMethodEx {
7
8
+ public static void main(String[] args) {
9
10
+ Set<String> words = new HashSet<>();
11
+ words.add("blue");
12
+ words.add("pen");
13
+ words.add("dog");
14
+ words.add("narrow");
15
16
+ Set<String> words2 = new HashSet<>();
17
18
+ words.add("pencil");
19
+ words.add("forest");
20
21
22
+ Set<String> res = union(words, words2);
23
+ System.out.println(res);
24
+ }
25
26
+ public static <E> Set<E> union(Set<E> s1, Set<E> s2) {
27
28
+ Set<E> result = new HashSet<>(s1);
29
+ result.addAll(s2);
30
31
+ return result;
32
33
+}
0 commit comments