public static void main(String[] args) {
        //异常代码
        /*List<String> a = new ArrayList<String>();
        a.add("1");
        a.add("2");
        for (String temp : a) {
            if ("2".equals(temp)) {
                a.remove(temp);
            }
            System.out.println(temp);
        }*/

        //正常代码
        List<String> a = new ArrayList<String>();
        a.add("1");
        a.add("2");
        //迭代器
        Iterator<String> iterator = a.iterator();
        while (iterator.hasNext()){
            String temp = iterator.next();
            if(temp == "2"){
                iterator.remove();
            }
        }
        System.out.println("______________");
        System.out.println(a.toString());
    }

 

相关文章:

  • 2021-08-01
  • 2021-10-31
  • 2021-10-27
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-06-28
  • 2022-12-23
  • 2022-12-23
  • 2022-02-08
  • 2022-02-13
  • 2022-01-06
  • 2022-12-23
相关资源
相似解决方案