0
下面的代碼是導致使用索引中移除元素的ArrayList中引起java.util.ConcurrentModificationException
java.util.ConcurrentModificationException
我不知道如何解決這個錯誤,請幫助!
ArrayList strList = new ArrayList<String>(Arrays.asList(cmd.split(" ")));
if (strList.get(0).equals("LIST")) {
}
if (strList.get(0).equals("DEPEND")) {
strList.remove(0); // getting error at this point
cm.createComponent(strList);
}
完整的方法外循環是不相關的列表
public static void main(String[] args) throws IOException {
ComponentManager cm = new ComponentManager();
List<String> lines = Files.readAllLines(Paths.get("cmdList.txt"));
for (String cmd : lines) {
ArrayList strList = new ArrayList<String>(Arrays.asList(cmd.split(" ")));
if (strList.get(0).equals("LIST")) {
}
if (strList.get(0).equals("DEPEND")) {
strList.remove(0);
cm.createComponent(strList);
}
if (strList.get(0).equals("INSTALL")) {
}
if (strList.get(0).equals("REMOVE")) {
}
}
}
你需要用戶迭代器, –
這裏沒有迭代。 – shmosel
沒有循環我只需要刪除第一個元素 –