-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
61 lines (52 loc) · 1.74 KB
/
Main.java
File metadata and controls
61 lines (52 loc) · 1.74 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package example.GenericExample;
/**
* Reference:
* - https://www.liaoxuefeng.com/wiki/1252599548343744/1265105853480864
*/
public class Main {
public static void main(String[] args) {
Integer[] intArray = {1, 2, 3, 4, 6};
Double[] doubleArray = {5.5, 4.4, 3.3, 4.1, 6.3};
Character[] charArray = {'H', 'E', 'L', 'L', 'O'};
String[] stringArray = {"UUU", "sssss", "You", "EEE"};
// displayArray(intArray);
// doubleArray(doubleArray);
// charArray(charArray);
// stringArray(stringArray);
System.out.println("int: " + getFirst(intArray));
System.out.println("double: " + getFirst(doubleArray));
System.out.println("char: " + getFirst(charArray));
System.out.println("string: " + getFirst(stringArray));
}
public static void displayArray(Integer[] array) {
for(Integer x : array) {
System.out.println(x + " ");
}
System.out.println();
}
public static void doubleArray(Double[] array) {
for(Double x : array) {
System.out.println(x + " ");
}
System.out.println();
}
public static void charArray(Character[] array) {
for(Character x : array) {
System.out.println(x + " ");
}
System.out.println();
}
public static void stringArray(String[] array) {
for(String x : array) {
System.out.println(x + " ");
}
System.out.println();
}
public static <T> T getFirst(T[] array) {
// for(T x : array) {
// System.out.println(x + " ");
// }
// System.out.println();
return array[0];
}
}