Skip to content

Instantly share code, notes, and snippets.

@deanveloper
Created January 23, 2017 20:28
Show Gist options
  • Save deanveloper/616bb1c206eb5b9d08634934305ba6f5 to your computer and use it in GitHub Desktop.
Save deanveloper/616bb1c206eb5b9d08634934305ba6f5 to your computer and use it in GitHub Desktop.
Boy howdy do you have to love iteration in Java.
package com.deanveloper;
import java.util.ArrayList;
import java.util.List;
/**
* @author Dean B <[email protected]>
*/
public class Test {
public static void main(String[] args) {
List<String> list = new ArrayList<>();
list.add("Hi");
list.add("How");
list.add("Are");
list.add("You");
for(String s : list) {
if(s.equals("Are")) {
list.remove(2);
}
System.out.println(s);
}
/* Output:
* Hi
* How
* Are
*/
System.out.println(list);
// Output:
// [Hi, How, You]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment