Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
599 B
1
Indexable
Never
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);
        }
    }
}
Leave a Comment