Sort by

recency

|

281 Discussions

|

  • + 0 comments
    class Printer
    {
         public static <T> void printArray (T[] element){
            for (T t : element) {
                System.out.println(t);
            }
        }
    }
    
  • + 1 comment

    public class Solution {

    public static<Integer, String> void printArray(int arr[],String arr1[]){
        for(int i = 0; i < arr.length; i++){
            System.out.println(arr[i]);
        }
        for(int i = 0; i < arr1.length; i++){
            System.out.println(arr1[i]);
        }
    
    }
    
    public static void main(String[] args) {
        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
        int [] arr = {1,2,3};
        String [] arr1 = {"Hello","World"};
        Solution s = new Solution();
        s.printArray(arr,arr1);
    
    }
    

    }

    • + 0 comments

      where is generic?

  • + 0 comments

    public class Solution {

    public static void main(String[] args) {
        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
        String [] strings = {"Hello", "World"};
        Integer[] ints = {1,2,3};
        print(ints);
        print(strings);
    }
    

    public static void print(T[] arr) { for (T item : arr) { System.out.println(item); } } }

  • + 0 comments
    import java.io.*;
    import java.util.*;
    
    public class Solution {
    
    
        public static <T> void genericDisplay(T[] arr)
        {
             for (T element: arr){
                System.out.println(element);
            } 
        }
        public static void main(String[] args) {
            /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
            
            String [] strings = {"Hello", "World"};
            Integer[] ints = {1,2,3};
            genericDisplay(ints);
            genericDisplay(strings);
            
            
        }
    }
    
  • + 0 comments

    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); }