import java.util.*;
public class Generics{
public static void main(String args[])
{
//generic version of ArrayList
ArrayList<String> l=new
ArrayList<String>();
List<String> l2=new
ArrayList<String>();
l2.add("list reference");
Collection<String> l3=new
ArrayList<String>();
l3.add("collection
reference");
//ArrayList<int> l1=new
ArrayList<int>();
//List<Object> l4=new
ArrayList<String>();
l.add("ramu");
l.add("dayina");
l.add("10"); //CE Gene.java:11: cannot find symbol
l.add(10);//CEsymbol: method
add(int) location: class
ArrayList<String>1 error
System.out.println(l);
System.out.println(l2);
System.out.println(l3);
//Collection(I)list(I) are the parent interfaces so they can hold the child references
List<Integer> l5=new
ArrayList<Integer>();
l5.add(100);
List<Integer> l6=new
LinkedList<Integer>();
l6.add(101);
List<Integer> l7=new
Vector<Integer>();
l7.add(102);
List<Integer> l8=new
Stack<Integer>();
l8.add(103);
System.out.println(l5);System.out.println(l6);System.out.println(l7);System.out.println(l8);
}}
D:\Threads>javac Generics.java
D:\Threads>java Generics
[ramu, dayina, 10]
[list reference]
[collection reference]
[100]
[101]
[102]
[103]
కామెంట్లు లేవు:
కామెంట్ను పోస్ట్ చేయండి