Sort by

recency

|

277 Discussions

|

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

  • + 0 comments

    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;

    for (Method method : Printer.class.getDeclaredMethods()) {
        String name = method.getName();
    
        if(name.equals("printArray"))
            count++;
    }
    
    if(count > 1)System.out.println("Method overloading is not allowed!");
    

    } }

  • + 0 comments

    /* * @Author : Rehan */ public static void printArray(T[] array){ for(T element : array){ System.out.println(element); } }

  • + 0 comments

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

  • + 0 comments

    static void printArray(T[] arr){

    for(T nums:arr){
    
    System.out.println(nums);
    
    }
    
    }