Sort by

recency

|

294 Discussions

|

  • + 0 comments

    This is a great exercise to understand the power of Java generics! Funinexchange Login

  • + 0 comments

    Yeah, the key here is to use a generic method instead of overloading—something like public static void printArray(T[] array) will handle both integers and strings. I learned that the simple approach often saves time, kind of like when I used rapidtestmedellin for quick and confidential health testing—it just worked smoothly without extra complications.

  • + 0 comments

    Giving 0 star to this qus.

    public static void main(String[] args) {
            /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
            List<Integer> arInt = new ArrayList<>();
            arInt.add(1);
            arInt.add(2);
            arInt.add(3);
            
            List<String> arStr = new ArrayList<>();
            arStr.add("Hello");
            arStr.add("World");
            printArray(arInt);
            printArray(arStr);
        }
        
        public static<T> void printArray(List<T> o){
            o.forEach(a -> System.out.println(a.toString()));
        }
    
  • + 0 comments

    In the spirit of the challenge:

        public static <T> void printArray(T[] array) {
            for( T e : array) {
                System.out.println(e);
            }
        }
    
        public static void main(String[] args) {
            Integer[] number = {1,2,3};
            String[] s = {"Hello", "World"};
            
            printArray(number);
            printArray(s);
        }
    
  • + 0 comments

    This challenge is poorly written. No challenge should be solved simply with:

    System.out.println("1");
    System.out.println("2");
    System.out.println("3");
    System.out.println("Hello");
    System.out.println("World");