-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathGenericMethods.java
More file actions
45 lines (37 loc) · 1.35 KB
/
GenericMethods.java
File metadata and controls
45 lines (37 loc) · 1.35 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
package Online_Code_Samples.Week2;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class GenericMethods {
public static void printIntList(List<Integer> intList){
for(Integer integer: intList){
System.out.printf("%s\t\t", integer);
}
}
public static void printStringList(List<String> stringList){
for(String string: stringList){
System.out.printf("%s\t\t", string);
}
}
public static void listPrinter(List<? extends Object> objectList){
for(Object object: objectList){
System.out.printf("%s\t\t", object.toString());
}
}
public static void main(String[] args) {
List<Integer> intList = new ArrayList<>();
intList.add(1); intList.add(2); intList.add(7);
List<Double> doubleList;
Double[] doubleArray = {1.1, 2.2, 3.3, 4.4, 5.5};
doubleList = Arrays.asList(doubleArray);
List<Character> charList;
Character[] characterArray = {'A', 'B', 'C', 'D', 'E'};
charList = Arrays.asList(characterArray);
List<String> stringList;
String[] stringArray = {"Boy", "Girl", "Woman", "Man", "Undecided"};
stringList = Arrays.asList(stringArray);
listPrinter(doubleList);
listPrinter(charList);
listPrinter(stringList);
}
}