We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
主要有以下3种方法:
使用Iterator的remove()方法的实现方式如下所示:
public static void main(String[] args) { List<String> platformList = new ArrayList<>(); platformList.add("博客园"); platformList.add("CSDN"); platformList.add("掘金"); Iterator<String> iterator = platformList.iterator(); while (iterator.hasNext()) { String platform = iterator.next(); if (platform.equals("博客园")) { iterator.remove(); } } System.out.println(platformList); }
输出结果为:
[CSDN, 掘金]
使用for循环正序遍历的实现方式如下所示:
public static void main(String[] args) { List<String> platformList = new ArrayList<>(); platformList.add("博客园"); platformList.add("CSDN"); platformList.add("掘金"); for (int i = 0; i < platformList.size(); i++) { String item = platformList.get(i); if (item.equals("博客园")) { platformList.remove(i); i = i - 1; } } System.out.println(platformList); }
使用for循环倒序遍历的实现方式如下所示:
public static void main(String[] args) { List<String> platformList = new ArrayList<>(); platformList.add("博客园"); platformList.add("CSDN"); platformList.add("掘金"); for (int i = platformList.size() - 1; i >= 0; i--) { String item = platformList.get(i); if (item.equals("掘金")) { platformList.remove(i); } } System.out.println(platformList); }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
主要有以下3种方法:
使用Iterator的remove()方法
使用Iterator的remove()方法的实现方式如下所示:
输出结果为:
[CSDN, 掘金]
使用for循环正序遍历
使用for循环正序遍历的实现方式如下所示:
使用for循环倒序遍历
使用for循环倒序遍历的实现方式如下所示:
The text was updated successfully, but these errors were encountered: