-
Notifications
You must be signed in to change notification settings - Fork 1
/
GenricsHR.java
36 lines (26 loc) · 1015 Bytes
/
GenricsHR.java
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
/*
Task
Write a single generic function named printArray; this function must take an array of generic elements as a parameter (the exception to this is C++, which takes a vector). The locked Solution class in your editor tests your function.
Note: You must use generics to solve this challenge. Do not write overloaded functions.
Input Format
The locked Solution class in your editor will pass different types of arrays to your printArray function.
Constraints
You must have exactly function named printArray.
Output Format
Your printArray function should print each element of its generic array parameter on a new line.
*/
// SOLUTION
import java.util.*;
class Printer <T> {
/**
* Method Name: printArray
* Print each element of the generic array on a new line. Do not return anything.
* @param A generic array
**/
// Write your code here
public static <E> void printArray(E[] generic){
for(E element : generic) {
System.out.println(element);
}
}
}