-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGenericBase.java
More file actions
39 lines (32 loc) · 1.16 KB
/
GenericBase.java
File metadata and controls
39 lines (32 loc) · 1.16 KB
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
package example.GenericExample;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/**
* Java泛型教學
*
* Reference:
* - https://tw511.com/20/209/8135.html
* - https://www.youtube.com/watch?v=K1iu1kXkVoA
* - https://www.cnblogs.com/jpfss/p/9928747.html
*/
public class GenericBase {
public static void main(String[] args) {
List<Integer> integerList = new ArrayList<Integer>();
integerList.add(Integer.valueOf(101));
integerList.add(Integer.valueOf(111));
List<String> stringList = new ArrayList<String>();
stringList.add("Java");
stringList.add("Python");
stringList.add("Javascript");
System.out.printf("Integer Value :%d\n", integerList.get(0));
System.out.printf("String Value :%s\n", stringList.get(0));
for (Integer data : integerList) {
System.out.printf("Integer Value :%d\n", data);
}
Iterator<String> stringIterator = stringList.iterator();
while (stringIterator.hasNext()) {
System.out.printf("String Value :%s\n", stringIterator.next());
}
}
}