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 Listfavorites = Arrays.asList("EJB", "JPA", "Glassfish", "NetBeans"); public static void main(String[] args){ System.out.println("favorites: " + favorites); }}