Created
January 23, 2017 20:28
-
-
Save deanveloper/616bb1c206eb5b9d08634934305ba6f5 to your computer and use it in GitHub Desktop.
Boy howdy do you have to love iteration in Java.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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