We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Java
- Data Structures
- Java Generics
- Discussions
Java Generics
Java Generics
Sort by
recency
|
277 Discussions
|
Please Login in order to post a comment
ArrayList arr=new ArrayList<>(); arr.add(1); arr.add(2); arr.add(3); arr.add("Hello"); arr.add("World"); for(Object i:arr) { System.out.println(i); }
import java.io.IOException; import java.lang.reflect.Method;
class Printer { public void printArray(T[] array) { for (T element : array) { System.out.println(element); }
} }
public class Solution {
public static void main( String args[] ) { Printer myPrinter = new Printer(); Integer[] intArray = { 1, 2, 3 }; String[] stringArray = {"Hello", "World"}; myPrinter.printArray(intArray); myPrinter.printArray(stringArray); int count = 0;
} }
/* * @Author : Rehan */ public static void printArray(T[] array){ for(T element : array){ System.out.println(element); } }
public static void main(String[] args) { Object[] arr = {1, 2, 3, "Hello", "World"}; printArray(arr); } static void printArray(T[] array){ for(T element: array){ System.out.println(element); } }
static void printArray(T[] arr){