提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
遍历ArrayList的元素
import java.util.ArrayList; import java.util.List; //from 时代Java公众号 - nowjava.com public class Main { public static void main(String[] args) { // Create an ArrayList of String List<String> nameList = new ArrayList<String>(); // Add some names nameList.add("A"); nameList.add("B"); nameList.add("C"); // Get the count of names in the list int count = nameList.size();/*来自 时 代 J a v a - N o w J a v a . c o m*/ // Let us print the name list System.out.println("List of names..."); for (int i = 0; i < count; i++) { String name = nameList.get(i); System.out.println(name); } // Let us remove Kathleen from the list nameList.remove("Kathleen"); // Get the count of names in the list again count = nameList.size(