Untitled
unknown
plain_text
2 years ago
599 B
6
Indexable
package JavaCollection;
/* write a single method printArray that can print all the elements of both arrays.
The method should be able to accept both integer arrays or string arrays.
*/
import java.util.Arrays;
public class JavaGenerics {
public static void main(String[] args) {
Integer array[] = {4, 5, 6};
String words[] = {"hello", "hi", "how"};
printArray(array);
printArray(words);
}
public static <T> void printArray(T[] arr) {
for (T element : arr) {
System.out.println(element);
}
}
}
Editor is loading...
Leave a Comment