程序是这样的
import java.net.*;
import java.util.*;
import org.jsoup.*;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
public class ArrayListDemo {
public static void main(String args[])throws Exception {
Parsing();
}
private static void Parsing() throws Exception{ //這是Parsing method
URL url = new URL("http://www.yahoo.com");
Document xmlDoc = Jsoup.parse(url,0);
Elements stock = xmlDoc.select("td");
ArrayList<String> hmi = new ArrayList<String>();
hmi.ensureCapacity(15);
hmi.add(""+stock.get(16));
System.out.println(hmi);
}
}
有如下错误
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 16, Size: 6
at java.util.ArrayList.rangeCheck(ArrayList.java:653)
at java.util.ArrayList.get(ArrayList.java:429)
at ArrayListDemo.Parsing(ArrayListDemo.java:18)
at ArrayListDemo.main(ArrayListDemo.java:9)
不明白为什么Arraylist size限制在6.如果将 hmi.add(""+stock.get(16))改为固定资料形态没有错误,例如: hmi.add("68"); 请问各位为什么这hmi.add(""+stock.get(16))语句不合法呢?谢谢.