@@ -0,0 +1,1825 @@
+package com.hello;%0A%0Aimport org.junit.Test;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.Iterator;%0Aimport java.util.List;%0A%0A/**%0A * @author dingxl%0A * @date 3/16/2021 7:05 PM%0A */%0Apublic class ListRemoveTest %7B%0A    @Test%0A    public void testListRemoveException() %7B%0A        List%3CString%3E list = new ArrayList%3CString%3E() %7B%7B%0A            add(%220%22);%0A            add(%221%22);%0A            add(%222%22);%0A            add(%223%22);%0A            add(%224%22);%0A        %7D%7D;%0A%0A        for (int i = 0; i %3C list.size(); i++) %7B%0A            if (i %25 2 == 0) %7B%0A                System.out.printf(%22remove: %25s%5Cn%22, list.get(i));%0A                list.remove(i);%0A            %7D else %7B%0A                System.out.printf(%22keep: %25s%5Cn%22, list.get(i));%0A            %7D%0A        %7D%0A    %7D%0A%0A    @Test%0A    public void testListRemove() %7B%0A        List%3CString%3E list = new ArrayList%3CString%3E() %7B%7B%0A            add(%220%22);%0A            add(%221%22);%0A            add(%222%22);%0A            add(%223%22);%0A            add(%224%22);%0A        %7D%7D;%0A%0A        for (int i = list.size() - 1; i %3E= 0; i--) %7B%0A            if (i %25 2 == 0) %7B%0A                System.out.printf(%22remove: %25s%5Cn%22, list.get(i));%0A                list.remove(i);%0A            %7D else %7B%0A                System.out.printf(%22keep: %25s%5Cn%22, list.get(i));%0A            %7D%0A        %7D%0A    %7D%0A%0A    @Test%0A    public void testIteratorRemove() %7B%0A        List%3CString%3E list = new ArrayList%3CString%3E() %7B%7B%0A            add(%220%22);%0A            add(%221%22);%0A            add(%222%22);%0A            add(%223%22);%0A            add(%224%22);%0A        %7D%7D;%0A%0A        Iterator%3CString%3E it = list.iterator();%0A        while (it.hasNext()) %7B%0A            String str = it.next();%0A            if (Integer.parseInt(str) %25 2 == 0) %7B%0A                System.out.printf(%22remove: %25s%5Cn%22, str);%0A                it.remove();%0A            %7D else %7B%0A                System.out.printf(%22keep: %25s%5Cn%22, str);%0A            %7D%0A        %7D%0A    %7D%0A%7D%0A

删除列表中元素的两个方法，list.remove(), iterator.remove()