Thursday, 8 June 2017

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


Click here to watch in Youtube :
https://www.youtube.com/watch?v=RA-2gwBjlPk&list=UUhwKlOVR041tngjerWxVccw

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

public class GenericDemo
{

    public static void main(String[] args)
    {
        GenericDemo genericDemo = new GenericDemo();
        
        ArrayList<Integer> numberList = new ArrayList<Integer>();
        numberList.add(100);
        numberList.add(200);
        genericDemo.processElements(numberList);
        
        System.out.println("--------------------------------");
        
        ArrayList<String> nameList = new ArrayList<String>();
        nameList.add("Peter");
        nameList.add("Ram");
        genericDemo.processElements(nameList);

    }

    public void processElements(List<?> list)
    {
        for (Object o : list)
        {
            System.out.println(o);
        }
    }

}
Output
100
200
--------------------------------
Peter
Ram
Click the below link to download the code:

CLICK HERE 

No comments:

Post a Comment