Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import org.junit.Test;
- import java.util.ConcurrentModificationException;
- import java.util.List;
- import java.util.stream.Collectors;
- import static java.util.stream.IntStream.range;
- public class ConcurrentModificationExceptionTest {
- @Test(expected = ConcurrentModificationException.class)
- public void shouldThrowWhileIteratingAndRemove() throws Exception {
- final List<Integer> ls = range(1, 100).boxed().collect(Collectors.toList());
- for (Integer l : ls) {
- System.out.println(l);
- ls.remove(l);
- }
- }
- @Test(expected = ConcurrentModificationException.class)
- public void shouldThrowWhileIteratingAndRemove_StreamApi() throws Exception {
- final List<Integer> ls = range(1, 100).boxed().collect(Collectors.toList());
- ls.stream().forEach(
- l -> {
- System.out.println(l);
- ls.remove(l);
- });
- }
- }
Add Comment
Please, Sign In to add comment