/**
时 代 J a v a 公 众 号 - nowjava.com
**/
import java.util.ArrayList;
public class Main
{
public static void main(String[] args)
{
// create a new ArrayList of Strings with an initial capacity of 10
ArrayList<String> items = new ArrayList<String>();
items.add("red"); // append an item to the list
items.add(0, "yellow"); // insert "yellow" at index 0
// header
System.out.println("Display list contents with counter-controlled loop:");
// display the colors in the list
for (int i = 0; i < items.size(); i++)
System.out.printf(" %s", items.get(i));
} /* 来 自 时代Java - N o w J a v a . c o m*/
// display the ArrayList's elements on the console
public static void display(ArrayList<String> items, String header)
{
System.out.print(header); // display header
/**代码未完, 请加载全部代码(NowJava.com).**/
本文系作者在时代Java发表,未经许可,不得转载。如有侵权,请联系nowjava@qq.com删除。