initialize a list when declaring it (zz)
With array, we can easily declare and initialize it at the same time:
String[] favorites = new String[] {"EJB", "JPA", "Glassfish", "NetBeans"};
Or even simpler:
String[] favorites = {"EJB", "JPA", "Glassfish", "NetBeans"};We can do the same with a List using java.util.Arrays.asList method. For example:
package javahowto;
import java.util.Arrays;
import java.util.List;
public class ListTest {
public static final List<String> favorites =
Arrays.asList("EJB", "JPA", "Glassfish", "NetBeans");
public static void main(String[] args){
System.out.println("favorites: " + favorites);
}
}

浙公网安备 33010602011771号