Welcome To The World Of Hacking


Learn Hacking|Teach Hacking|Learn To Secure|Learn To Code

Friday

JAVA PROGRAMMING TUTORIAL 37 : GENERIC METHOD

// Generic method is a way to eliminate overloaded method

import java.util.*;

public class HackDefence{

public static void main(String[] args){

Integer[] intG = {0,1,2,3,4,5,6,7,8,9};

Character[] chG ={'d','i','p','a','n','k','a','r'};

System.out.println("Display using Generic method->");

displayGeneric(intG);

displayGeneric(chG);

}

public static <T> void displayGeneric(T[] g){

          for(T d : g)

            System.out.printf("%s ",d);

System.out.println();

}

}

OUTPUT:

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...