This post originated from an RSS feed registered with Java Buzz
by dion.
Original Post: JDK 1.5: Arrays.asList("Rod", "James", "Chris")
Feed Title: techno.blog(Dion)
Feed URL: http://feeds.feedburner.com/dion
Feed Description: blogging about life the universe and everything tech
J Yu pointed out that, thanks to JDK 1.5, generics, and varargs, we now have a really nice way to simply create a List of stuff:
Was:
List list = new java.util.ArrayList();
list.add( "Rod" ); list.add( "James" ); list.add( "Chris" );
1.5:
List list = Arrays.asList("Rod", "James", "Chris");
or, with generics:
List list = Arrays.asList("Rod", "James", "Chris");
Arrays.asList(..) was always around, but it changed from:
public static List asList(Object a)
to the nicer, if more cryptic:
public static <T> List<T> asList(T... a)