Thursday, 8 June 2017

Java Tutorial: Generics in java | Java Generics [Unbounded wildcard in Java Generics] ~ foundjava


Click here to watch in Youtube :
https://www.youtube.com/watch?v=S8vM6LMdvq8&list=UUhwKlOVR041tngjerWxVccw

Click the below Image to Enlarge
Java Tutorial: Generics in java | Java Generics [Unbounded wildcard in Java Generics] 
GenericDemo.java
import java.util.ArrayList;
import java.util.List;

public class GenericDemo
{

    public static void main(String[] args)
    {
        List<String> nameList = new ArrayList<String>();
        nameList.add("Peter");
        nameList.add("Ram");
        printData(nameList);
        
        System.out.println("--------------------------");
        
        List<Integer> integerList = new ArrayList<Integer>();
        integerList.add(2);
        integerList.add(3);
        integerList.add(5);
        printData(integerList);

    }

    public static void printData(List<?> list)
    {
        for (Object obj : list)
        {
            System.out.println(obj);
        }
    }

}
Output
Peter
Ram
--------------------------
2
3
5
Click the below link to download the code:

CLICK HERE

No comments:

Post a Comment