Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save forAllBright/51d79369040e8e6b185f01797a2ea797 to your computer and use it in GitHub Desktop.
Save forAllBright/51d79369040e8e6b185f01797a2ea797 to your computer and use it in GitHub Desktop.
Java Tricks #Java #FalliblePoint
// 在 for 的高级用法中不能动态的删除集合元素。
public class Test {
public static void main(String[] args) {
ArrayList<String> str = new ArrayList<>();
str.add("h");
str.add("e");
str.add("ll");
str.add("o");
for(String i:str) {
if(i.equals("e")) {
str.remove(i);
}
}
System.out.println(str);
@Lushiane
Copy link

Can u help me with this code? I'm a beginner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment