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] |
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);
}
}
}
OutputPeter
Ram
--------------------------
2
3
5
Click the below link to download the code:
No comments:
Post a Comment