In this HackerRank Java Generics problem, you have to 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.

HackerRank Java Generics problem solution

HackerRank Java Generics problem solution

class Printer {

	public void printArray(Object[] array) {
		if (array instanceof Integer[]) {
			Integer[] intArray = (Integer[]) array;
			for (Integer i : intArray) {
				System.out.println(i);
			}
		} else if (array instanceof String[]) {
			String[] stringArray = (String[]) array;
			for (String s : stringArray) {
				System.out.println(s);
			}
		}
	}

}