看板 java 關於我們 聯絡資訊
小弟想試試ArrayList的用法...所以寫了一個小程式如下 import java.util.*; public class ArrayListTest2 { public static void main(String[] args) { ArrayListTest2 alt = new ArrayListTest2(); alt.workHorse(); } public void workHorse() { int a = 5; ArrayList al = new ArrayList(); al.add(1,a); } } 結果compile出現 C:\practice\ArrayListTest2.java:13: cannot resolve symbol symbol : method add (int,int) location: class java.util.ArrayList al.add(1,a); ^ 1 error 但如果我把丟入add()的值換成String類型而非int就可compile ArrayList不是只要是物件就能丟嗎?? 請問發生錯誤的原因為何? 另外...如果我想抓出ArrayList中特定位置的資料...請問該用什麼語法啊? 是get(int i)嗎? 煩請各位高手指教....~.~ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 218.161.17.247