Wednesday, March 4, 2009

source code generics



package mygenerics;

import java.util.ArrayList;

public class MethodGen {
public static void main(String arg[])
{
ArrayList<String> l=new ArrayList <String >();
l.add("a");
l.add("b");
l.add("c");
show(l);
}
public static void show(ArrayList<String> l)
{
System.out.println(l.get(0));
System.out.println(l.get(1));
System.out.println(l.get(2));
// Here get method returns string no need type cast

}
}



0 comments:

Post a Comment