Java examples for Collection Framework:List
Use an ArrayList.
import java.util.ArrayList; import java.util.List; public class Main { public static void main(String[] args) { List<String> stocks = new ArrayList<>(); stocks.add("ORCL"); stocks.add("AAPL"); stocks.add("GOOG"); stocks.add("IBM"); stocks.add("MCD"); System.out.println("stocks: " + stocks); }/* w ww . jav a 2s . c o m*/ }