-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtilitiesTest.java
More file actions
27 lines (24 loc) · 940 Bytes
/
Copy pathUtilitiesTest.java
File metadata and controls
27 lines (24 loc) · 940 Bytes
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
/*------------------------------------------------------------------------------
* Oracle Certified Professional Java SE 8 Programmer Exam 1Z0-809
* A Comprehensive OCPJP 8 Certification Guide
* by SG Ganesh, Hari Kiran and Tushar Sharma
------------------------------------------------------------------------------*/
// This program demonstrates generic methods
import java.util.List;
import java.util.ArrayList;
class Utilities {
public static <T> void fill(List<T> list, T val) {
for(int i = 0; i < list.size(); i++)
list.set(i, val);
}
}
class UtilitiesTest {
public static void main(String []args) {
List<Integer> intList = new ArrayList<Integer>();
intList.add(10);
intList.add(20);
System.out.println("The original list is: " + intList);
Utilities.fill(intList, 100);
System.out.println("The list after calling Utilities.fill() is: " + intList);
}
}