Java examples for Collection Framework:List
Creating a Type-specific Collection Using Generics
import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; import java.util.List; public class Main { public void m() { List<Integer> intlist = new ArrayList<Integer>(); intlist.add(new Integer(123)); intlist.add(null);//from ww w . ja v a 2 s .c o m List<Number> numlist = new ArrayList<Number>(); numlist.add(new Integer(123)); numlist.add(new Float(123)); List<URL> urlList = new ArrayList<URL>(); try { urlList.add(new URL("http://java2s.com")); } catch (MalformedURLException e) { } String s = urlList.get(0).getHost(); } }