似乎無法獲得此權限。我錯過了什麼?發現無法從陣列列表中刪除此字符串
3個錯誤:
File: K:\CustomerLister2.java [line: 16] Error: The method length() is undefined for the type java.util.ArrayList File:
K:\CustomerLister2.java [line: 18] Error: The type of the expression must be an array type but it resolved to
java.util.ArrayList File: K:\CustomerLister2.java [line: 20] Error: The type of the expression must be an array type but it resolved to java.util.ArrayList
import java.util.ArrayList;
public class CustomerLister2 {
public static void main (String[] args) {
ArrayList<String> name = new ArrayList<String>();
name.add("Chris");
name.add("Lois");
name.add("Meg");
name.add("Meg");
name.add("Brain");
name.add("Peter");
name.add("Stewie");
for (int i = 0; i < name.length(); i++) {
if (name[i].equals("Meg")) {
name[i] = null;
break;
}
for(String names: name) {
System.out.println(names);
}
}
}
}