Java  Collection ・Map 例題 100本ノック

次のコードの出力を答えてください。

変数は、以降の問題に引き継いでいくと考えてください。

# 問1

```java
List<Integer> list = new ArrayList<>(Arrays.asList(0, 1, 2, 4));
List<Integer> list2 = new ArrayList<>(Arrays.asList(1, 3));
```
```java
System.out.println(list.add(5));
System.out.println(list);
```

<details>
<summary>問1の解答</summary>
<pre class="console">true
[0, 1, 2, 4, 5]
</pre>
</details>

# 問2
```java
System.out.println(list.addAll(list2));
System.out.println(list);
```

<details>
<summary>問2の解答</summary>
<pre class="console">true
[0, 1, 2, 4, 5, 1, 3]</pre>
</details>

# 問3
```java
System.out.println(list.add(1, 2));
System.out.println(list);
```

<details>
<summary>問3の解答</summary>
戻り値voidなのでコンパイルエラー

`void add​(int index, E element)`
コンパイルエラーが発生した操作の要素の変化は無視してください。
</details>

# 問4

```java
System.out.println(list.set(2, 10));
System.out.println(list);
```

<details>
<summary>問4の解答</summary>
<pre class="console">2
[0, 1, 10, 4, 5, 1, 3]</pre>
</details>

# 問5
```java
System.out.println(list.remove(1));
System.out.println(list);
```

<details>
<summary>問5の解答</summary>
<pre class="console">1
[0, 10, 4, 5, 1, 3]</pre>

Listインターフェイスで独自に定義された`E remove(int index)`は要素のインデックス番号がindexの要素を取り除き、返します。
Collectionインターフェイスの`boolean remove(Object obj)`では要素そのものを取り除きます。
問題では、removeメソッドの引数の型がint型です。
Listインターフェイスの`E remove(int index)`が呼び出されます。

</details>

# 問6
```java
System.out.println(list.remove(Integer.valueOf(3)));
System.out.println(list);
```

<details>
<summary>問6の解答</summary>
<pre class="console">true
[0, 10, 4, 5, 1]</pre>
</details>

# 問7
```java
System.out.println(list.removeAll(list2));
System.out.println(list);
```

<details>
<summary>問7の解答</summary>
<pre class="console">true
[0, 10, 4, 5]</pre>
</details>

# 問8
```java
System.out.println(list.retainAll(list2));
System.out.println(list);
```

<details>
<summary>問8の解答</summary>
<pre class="console">true
[]</pre>
</details>

# 問9
```java
System.out.println(list.clear());
```

<details>
<summary>問9の解答</summary>voidなのでコンパイルエラー
</details>

# 問10
```java
System.out.println(list.isEmpty());
```

<details>
<summary>問10の解答</summary>
<pre class="console">true</pre>
</details>


# 問11
```java
System.out.println(list.remove(1));
```

<details>
<summary>問11の解答</summary>

`java.lang.IndexOutOfBoundsException`がスローされる
</details>

初期化
```java
SortedSet<Integer> set = new TreeSet<>(Arrays.asList(0, 1, 2, 3, 4));
```


# 問12
```java
System.out.println(set.add(0));
```

<details>
<summary>問12の解答</summary>
<pre class="console">false</pre>
</details>

# 問13
```java
System.out.println(set.first());
```

<details>
<summary>問13の解答</summary>
<pre class="console">0</pre>
</details>


# 問14
```java
System.out.println(set.last());
System.out.println(set);
```

<details>
<summary>問14の解答</summary>
<pre class="console">4
[0, 1, 2, 3, 4]</pre>
</details>


# 問15
```java
System.out.println(set.tailSet(1));
System.out.println(set.headSet(1));
```

<details>
<summary>問15の解答</summary>
<pre class="console">[1, 2, 3, 4]
[0]</pre>
</details>


# 問16
```java
System.out.println(set.subSet(0, 2));
System.out.println(set);
```

<details>
<summary>問16の解答</summary>
<pre class="console">[0, 1]
[0, 1, 2, 3, 4]</pre>
</details>


# 問17
```java
System.out.println(set.contains(4));
```

<details>
<summary>問17の解答</summary>
<pre class="console">true</pre>
</details>

# 問18
```java
Set<Integer> set2 = new TreeSet<>(Arrays.asList(2, 3));
System.out.println(set.containsAll(set2));
```

<details>
<summary>問18の解答</summary>
<pre class="console">true</pre>
</details>

初期化
```java
Queue<Integer> que = new LinkedList<>(Arrays.asList(0, 1, 2));
```


# 問19
```java
System.out.println(que.add(3));
```

<details>
<summary>問19の解答</summary>
<pre class="console">true</pre>
</details>

# 問20
```java
System.out.println(que.offer(4));
System.out.println(que);
```

<details>
<summary>問20の解答</summary>
<pre class="console">true
[0, 1, 2, 3, 4]</pre>
</details>

# 問21
```java
System.out.println(que.remove());
System.out.println(que);
```

<details>
<summary>問21の解答</summary>
<pre class="console">0
[1, 2, 3, 4]</pre>
</details>

# 問22
```java
System.out.println(que.remove(2));
System.out.println(que);
```

<details>
<summary>問22の解答</summary>
<pre class="console">true
[1, 3, 4]</pre>

Listインターフェイスと異なり、Queueインターフェイスでは`E remove(int index)`は定義されていない。
そのため、Collectionインターフェイスの`boolean remove(Object obj)`が適用されるため注意。
</details>

# 問23
```java
System.out.println(que.element());
System.out.println(que);
```

<details>
<summary>問23の解答</summary>
<pre class="console">1
[1, 3, 4]</pre>
</details>


# 問24
```java
System.out.println(que.poll());
System.out.println(que);
```

<details>
<summary>問24の解答</summary>
<pre class="console">1
[3, 4]</pre>
</details>


# 問25
```java
System.out.println(que.peek());
System.out.println(que);
```

<details>
<summary>問25の解答</summary>
<pre class="console">3
[3, 4]</pre>
</details>


# 問26
```java
que.clear();
System.out.println(que.poll());
```

<details>
<summary>問26の解答</summary>
<pre class="console">null</pre>
</details>


# 問27
```java
System.out.println(que.peek());
```

<details>
<summary>問27の解答</summary>
<pre class="console">null</pre>
</details>


# 問28
```java
System.out.println(que.element());
```

<details>
<summary>問28の解答</summary>

`NoSuchElementException`がスローされる。
</details>


# 問29
```java
System.out.println(que.remove());
```

<details>
<summary>問29の解答</summary>

`NoSuchElementException`がスローされる。
</details>


初期化
```java
Deque<Integer> dque = new LinkedList<>(Arrays.asList(0, 1, 2, 3));
```

# 問30
```java
System.out.println(dque.offer(4));
System.out.println(dque);
```

<details>
<summary>問30の解答</summary>
<pre class="console">true
[0, 1, 2, 3, 4]</pre>
</details>


# 問31
```java
System.out.println(dque.addLast(4));
System.out.println(dque);
```

<details>
<summary>問31の解答</summary>

`void addLast(Integer e)`
戻り値voidのためコンパイルエラー
</details>


# 問32
```java
dque.addLast(4);
System.out.println(dque);
```

<details>
<summary>問32の解答</summary>
<pre class="console">[0, 1, 2, 3, 4, 4]</pre>
</details>


# 問33
```java
dque.addFirst(3);
System.out.println(dque);
```

<details>
<summary>問33の解答</summary>
<pre class="console">[3, 0, 1, 2, 3, 4, 4]</pre>
</details>


# 問34
```java
System.out.println(dque.removeFirst());
System.out.println(dque);
```

<details>
<summary>問34の解答</summary>
<pre class="console">3
[0, 1, 2, 3, 4, 4]</pre>
</details>


# 問35
```java
System.out.println(dque.removeLast());
System.out.println(dque);
```

<details>
<summary>問35の解答</summary>
<pre class="console">4
[0, 1, 2, 3, 4]</pre>
</details>


# 問36
```java
System.out.println(dque.pollFirst());
```

<details>
<summary>問36の解答</summary>
<pre class="console">0</pre>
</details>


# 問37
```java
System.out.println(dque.pollLast());
System.out.println(dque);
```

<details>
<summary>問37の解答</summary>
<pre class="console">4
[1, 2, 3]</pre>
</details>


# 問38
```java
System.out.println(dque.getFirst());
```

<details>
<summary>問38の解答</summary>
<pre class="console">1</pre>
</details>


# 問39
```java
System.out.println(dque.getLast());
System.out.println(dque);
```

<details>
<summary>問39の解答</summary>
<pre class="console">3
[1, 2, 3]</pre>
</details>


# 問40
```java
System.out.println(dque.peekFirst());
```

<details>
<summary>問40の解答</summary>
<pre class="console">1</pre>
</details>


# 問41
```java
System.out.println(dque.peekLast());
System.out.println(dque);
```

<details>
<summary>問41の解答</summary>
<pre class="console">3
[1, 2, 3]</pre>
</details>


# 問42
```java
dque = new LinkedList<>(Arrays.asList(0, 1, 2, 0, 1, 2, 0, 3, 2, 1));
System.out.println(dque.removeFirstOccurrence(1));
System.out.println(dque);
```

<details>
<summary>問42の解答</summary>
<pre class="console">true
[0, 2, 0, 1, 2, 0, 3, 2, 1]</pre>
</details>

# 問43
```java
System.out.println(dque.removeLastOccurrence(2));
System.out.println(dque);
```

<details>
<summary>問43の解答</summary>
<pre class="console">true
[0, 2, 0, 1, 2, 0, 3, 1]</pre>
</details>


# 問44
```java
dque.clear();
System.out.println(dque.pollFirst());
```

<details>
<summary>問44の解答</summary>
<pre class="console">null</pre>
</details>


# 問45
```java
System.out.println(dque.pollLast());
```

<details>
<summary>問45の解答</summary>
<pre class="console">null</pre>
</details>


# 問46
```java
System.out.println(dque.peekFirst());
```

<details>
<summary>問46の解答</summary>
<pre class="console">null</pre>
</details>

# 問47
```java
System.out.println(dque.peekLast());
```

<details>
<summary>問47の解答</summary>
<pre class="console">null</pre>
</details>


# 問48
```java
System.out.println(dque.removeFirstOccurrence(1));
```

<details>
<summary>問48の解答</summary>
<pre class="console">false</pre>
</details>


# 問49
```java
System.out.println(dque.removeFirst());
```

<details>
<summary>問49の解答</summary>

`java.util.NoSuchElementException`がスローされる
</details>


# 問50
```java
System.out.println(dque.getFirst());
```

<details>
<summary>問50の解答</summary>
`java.util.NoSuchElementException`がスローされる
</details>

初期化
```java
NavigableSet<Integer> set =	new TreeSet<>(Arrays.asList(30, 10, 20, 40));
```

# 問51
```java
System.out.println(set.poll());
set.poll();
```

<details>
<summary>問51の解答</summary>

`NavigableSet`には`poll()`メソッドが存在しないためコンパイルエラー

</details>



# 問52
```java
System.out.println(set.pollFirst());
System.out.println(set);
```

<details>
<summary>問52の解答</summary>
<pre class="console">10
[20, 30, 40]</pre>
</details>



# 問53
```java
System.out.println(set.lower(30));
System.out.println(set);
```

<details>
<summary>問53の解答</summary>
<pre class="console">20
[20, 30, 40]</pre>
</details>


# 問54
```java
System.out.println(set.floor(30));
System.out.println(set);
```

<details>
<summary>問54の解答</summary>
<pre class="console">30
[20, 30, 40]</pre>
</details>


# 問55
```java
System.out.println(set.ceiling(31));
System.out.println(set);
```

<details>
<summary>問55の解答</summary>
<pre class="console">40
[20, 30, 40]</pre>
</details>


# 問56
```java
System.out.println(set.higher(30));
System.out.println(set);
```

<details>
<summary>問56の解答</summary>
<pre class="console">40
[20, 30, 40]</pre>
</details>


# 問57
```java
System.out.println(set.higher(40));
System.out.println(set);
```

<details>
<summary>問57の解答</summary>
<pre class="console">null
[20, 30, 40]</pre>
</details>


# 問58
```java
System.out.println(set.descendingSet());
System.out.println(set);
```

<details>
<summary>問58の解答</summary>
<pre class="console">[40, 30, 20]
[20, 30, 40]</pre>
戻り値は要素を反転させたビュー
</details>


# 問59
```java
System.out.println(set.headSet(30));
```

<details>
<summary>問59の解答</summary>
<pre class="console">[20]</pre>
</details>


# 問60
```java
System.out.println(set.tailSet(30));
```

<details>
<summary>問60の解答</summary>
<pre class="console">[30, 40]</pre>
</details>


# 問61
```java
System.out.println(set.subSet(20, 30));
System.out.println(set);
```

<details>
<summary>問61の解答</summary>
<pre class="console">[20]
[20, 30, 40]</pre>
</details>


# 問62
```java
System.out.println(set.subSet(20, true, 30, true));
```

<details>
<summary>問62の解答</summary>
<pre class="console">[20, 30]</pre>
</details>


# 問63
初期化
```java
Map<Integer, String> treeMap = new TreeMap<>();
int[] keys = {30, 10, 20, 40};
String[] values = {"A", "B", "C", "D"};
for (int i = 0; i < keys.length; i++) {
    treeMap.put(keys[i], values[i]);
}
```
```java
System.out.println(treeMap);
```
<details>
<summary>問64の解答</summary>
<pre class="console">{10=B, 20=C, 30=A, 40=D}</pre>
</details>


# 問65
```java
System.out.println(treeMap.put(10, "E"));
System.out.println(treeMap);
```

<details>
<summary>問65の解答</summary>
<pre class="console">B
{10=E, 20=C, 30=A, 40=D}</pre>
</details>


# 問66
```java
System.out.println(treeMap.get(20));
```

<details>
<summary>問66の解答</summary>
<pre class="console">C</pre>
</details>


# 問67
```java
System.out.println(treeMap.contains(10));
```

<details>
<summary>問67の解答</summary>

Mapに`contains(K)`メソッドは存在しないため、コンパイルエラー
</details>


# 問68
```java
System.out.println(treeMap.containsKey(10));
System.out.println(treeMap);
```

<details>
<summary>問68の解答</summary>
<pre class="console">true
{10=E, 20=C, 30=A, 40=D}</pre>
</details>


# 問69
```java
System.out.println(linkedHashMap.containsValue("B"));
```

<details>
<summary>問69の解答</summary>
<pre class="console">false</pre>
</details>


# 問70
```java
System.out.println(treeMap.putIfAbsent(50, "F"));
System.out.println(treeMap.putIfAbsent(50, "G"));
System.out.println(treeMap);
```

<details>
<summary>問70の解答</summary>
<pre class="console">null
F
{10=E, 20=C, 30=A, 40=D, 50=F}</pre>
</details>


# 問71
```java
System.out.println(treeMap.compute(30, (k, v) -> v + "aaa"));
System.out.println(treeMap);
```

<details>
<summary>問71の解答</summary>
<pre class="console">Aaaa
{10=E, 20=C, 30=Aaaa, 40=D, 50=F}</pre>
</details>


# 問72
```java
System.out.println(treeMap.computeIfAbsent(10, k -> "bbb"));
System.out.println(treeMap.computeIfAbsent(60, k -> "bbb"));
System.out.println(treeMap);
```

<details>
<summary>問72の解答</summary>
<pre class="console">E
bbb
{10=E, 20=C, 30=Aaaa, 40=D, 50=F, 60=bbb}</pre>
</details>


# 問73
```java
System.out.println(treeMap.computeIfPresent(10, (k, v) -> v + "ccc"));
System.out.println(treeMap.computeIfPresent(10, (k, v) -> v + "ddd"));
System.out.println(treeMap);
```

<details>
<summary>問73の解答</summary>
<pre class="console">Eccc
Ecccddd
{10=Ecccddd, 20=C, 30=Aaaa, 40=D, 50=F, 60=bbb}</pre>
</details>


# 問74
```java
System.out.println(treeMap.merge(20, " merge", (v1, v2) -> v1 + v2));
System.out.println(treeMap);
```

<details>
<summary>問74の解答</summary>
<pre class="console">C merge
{10=Ecccddd, 20=C merge, 30=Aaaa, 40=D, 50=F, 60=bbb}</pre>
</details>


# 問75
```java
TreeMap<Integer, String> treeMap2 = new TreeMap<>();
int[] keys2 = {30, 10, 20, 40};
String[] values2 = {"A", "B", "C", "D"};
for (int i = 0; i < keys2.length; i++) {
    treeMap2.put(keys2[i], values2[i]);
}
System.out.println(treeMap2.entrySet());
```

<details>
<summary>問75の解答</summary>
<pre class="console">[10=B, 20=C, 30=A, 40=D]</pre>
</details>


# 問76
```java
System.out.println(treeMap2.remove(10));
System.out.println(treeMap2.remove(10));
System.out.println(treeMap2);
```

<details>
<summary>問76の解答</summary>
<pre class="console">B
null
{20=C, 30=A, 40=D}</pre>
</details>


# 問77
```java
System.out.println(treeMap2.keySet());
```

<details>
<summary>問77の解答</summary>
<pre class="console">[20, 30, 40]</pre>
</details>


# 問78
```java
System.out.println(treeMap2.clear());
```

<details>
<summary>問78の解答</summary>

`clear()`メソッドの戻り値はvoidなのでコンパイルエラー
</details>


# 問79
```java
System.out.println((treeMap2).firstEntry());
```

<details>
<summary>問79の解答</summary>
<pre class="console">20=C</pre>
</details>


# 問80
```java
System.out.println(treeMap2.firstKey());
System.out.println(treeMap2.lastKey());
System.out.println(treeMap2);
```

<details>
<summary>問80の解答</summary>
<pre class="console">20
40
{20=C, 30=A, 40=D}</pre>
</details>


# 問81
```java
System.out.println(treeMap2.floorEntry(30));
System.out.println(treeMap2.floorEntry(25));
System.out.println(treeMap2);
```

<details>
<summary>問81の解答</summary>
<pre class="console">30=A
20=C
{20=C, 30=A, 40=D}</pre>
</details>


# 問82
```java
System.out.println(treeMap2.headMap(40));
System.out.println(treeMap2);
```

<details>
<summary>問82の解答</summary>
<pre class="console">{20=C, 30=A}
{20=C, 30=A, 40=D}</pre>
</details>


# 問83
```java
System.out.println(treeMap2.tailMap(30));
System.out.println(treeMap2);
```

<details>
<summary>問83の解答</summary>
<pre class="console">{30=A, 40=D}
{20=C, 30=A, 40=D}</pre>
</details>


# 問84
```java
Map<Integer, String> linkedHashMap = new LinkedHashMap<>();
int[] keys = {30, 10, 20, 40};
String[] values = {"A", "B", "C", "D"};
for (int i = 0; i < keys.length; i++) {
    linkedHashMap.put(keys[i], values[i]);
}

System.out.println(linkedHashMap);
```

<details>
<summary>問84の解答</summary>
<pre class="console">{30=A, 10=B, 20=C, 40=D}</pre>
</details>


# 問85
```java
System.out.println(linkedHashMap.values());
```

<details>
<summary>問85の解答</summary>
<pre class="console">[A, B, C, D]</pre>
</details>


# 問86 
これ以降、各問題の変数は引き継がないものとして考えてください。
```java
Collection<String> list = new ArrayList<>(Arrays.asList("A", "B", "C", "D"));
list.removeAll(Arrays.asList("B", "D", "E"));
System.out.println(list);
```

<details>
<summary>問86の解答</summary>
<pre class="console">[A, C]
</pre>
</details>

# 問87

```java
Collection<String> list = new ArrayList<>();
list.add("A");
list.add("B");
list.clear();
System.out.println(list.isEmpty());
```

<details>
<summary>問87の解答</summary>
<pre class="console">true
</pre>
</details>


# 問88
```java
Queue<String> queue = new LinkedList<>(Arrays.asList("first", "second", "third"));
queue.add("fourth");
queue.poll();
queue.offer("fifth");
queue.remove("third");
System.out.println(queue);
```
<details>
<summary>問88の解答</summary>
<pre class="console">[second, fourth, fifth]
</pre>
</details>


# 問89

```java
Collection<Integer> set = new HashSet<>(Arrays.asList(1, 2, 3, 4));
set.retainAll(Arrays.asList(2, 4, 6));
System.out.println(set);
```

<details>
<summary>問89の解答</summary>
<pre class="console">[2, 4]
</pre>
</details>


# 問90

```java
Collection<String> list = new LinkedList<>(Arrays.asList("X", "Y", "Z"));
Iterator<String> iterator = list.iterator();
while (iterator.hasNext()) {
    String value = iterator.next();
    if (value.equals("Y")) {
        iterator.remove();
    }
}
System.out.println(list);
```

<details>
<summary>問90の解答</summary>
<pre class="console">[X, Z]
</pre>
</details>


# 問91

```java
Collection<Integer> list = new ArrayList<>();
list.add(1);
list.add(2);
list.add(3);
list.addAll(Arrays.asList(4, 5));
list.removeIf(n -> n % 2 == 0);
System.out.println(list);
```

<details>
<summary>問91の解答</summary>
<pre class="console">[1, 3, 5]
</pre>
</details>


# 問92

```java
Collection<Integer> list = new LinkedList<>(Arrays.asList(1, 2, 3));
Iterator<Integer> iterator = list.iterator();
while (iterator.hasNext()) {
    Integer value = iterator.next();
    if (value > 1) {
        iterator.remove();
    }
}
System.out.println(list);
```

<details>
<summary>問92の解答</summary>
<pre class="console">1
</pre>
</details>


# 問93

```java
Collection<String> list = new ArrayList<>(Arrays.asList("A", "B", "C", "D"));
list.removeIf(s -> "B".equals(s));
System.out.println(list);
```

<details>
<summary>問93の解答</summary>
<pre class="console">[A, C, D]
</pre>
</details>


# 問94

```java
List<Integer> list = new ArrayList<>(Arrays.asList(1, 2, 3, 4, 5));
List<Integer> subList = list.subList(1, 4);
subList.replaceAll(n -> n * 2);
System.out.println(list);
```

<details>
<summary>問94の解答</summary>
<pre class="console">[1, 4, 6, 8, 5]
</pre>
subListメソッドで取得したサブリストに対してreplaceAllメソッドを呼び出すと、そのサブリストに対する変更が元のリストにも反映されます。
</details>


# 問95

```java
Collection<String> list = new LinkedList<>(Arrays.asList("alpha", "beta", "gamma"));
ListIterator<String> iterator = ((LinkedList<String>)list).listIterator(1);
iterator.next();
iterator.set("delta");
System.out.println(list);
```

<details>
<summary>問95の解答</summary>
<pre class="console">[alpha, delta, gamma]
</pre>
listIterator(1)はインデックス1の要素("beta")を指すリストイテレータを作成します。次に、iterator.set("delta")で"beta"を"delta"に置き換えます。
</details>


# 問96

```java
Collection<String> list = new ArrayList<>(Arrays.asList("A", "B", "C"));
List<String> subList = ((ArrayList<String>)list).subList(1, 3);
subList.clear();
System.out.println(list);
```

<details>
<summary>問96の解答</summary>
<pre class="console">[A]
</pre>
subList(1, 3)はインデックス1から2の範囲のサブリストを返します。subList.clear()はそのサブリストを空にし、オリジナルのリストからも要素"B"と"C"が削除されます。
</details>


# 問97

```java
Collection<Integer> set = new HashSet<>(Arrays.asList(1, 2, 3));
set.add(null);
boolean result = set.removeIf(Objects::isNull);
System.out.println(result);
System.out.println(set);
```

<details>
<summary>問97の解答</summary>
<pre class="console">true
[1, 2, 3]
</pre>
removeIf(Objects::isNull)は、null要素を削除します。nullが存在するためtrueが返され、残った要素は[1, 2, 3]です。
</details>


# 問98

```java
Collection<String> list = new ArrayList<>(Arrays.asList("X", "Y", "Z"));
Iterator<String> iterator = list.iterator();
while (iterator.hasNext()) {
    String value = iterator.next();
    list.remove(value);
}
System.out.println(list);
```

<details>
<summary>問98の解答</summary>
イテレータでリストをループしている最中に直接リストの要素を変更すると
ConcurrentModificationExceptionがスローされる
</details>


# 問99

```java
Collection<Integer> set = new TreeSet<>(Arrays.asList(5, 3, 1, 4, 2));
NavigableSet<Integer> subSet = ((TreeSet<Integer>)set).subSet(2, true, 4, true);
subSet.add(3);
System.out.println(subSet);
System.out.println(set);
```

<details>
<summary>問99の解答</summary>
<pre class="console">[2, 3, 4]
[1, 2, 3, 4, 5]
</pre>
NavigableSet.subSet(2, true, 4, true)で得られるサブセットには、2から4までの要素が含まれます。
</details>


# 問100

```java
Collection<String> list = new ArrayList<>(Arrays.asList("A", "B", "C", "D"));
list.removeIf(s -> list.add("E"));
System.out.println(list);
```

<details>
<summary>問100の解答</summary>
s -> list.add("E")がリストに対して変更を加えるため、removeIfメソッドが実行中にリストが変更されることになります
そのためConcurrentModificationExceptionがスローされます
</details>

:::note
Document
[`Collection`](https://docs.oracle.com/javase/jp/11/docs/api/java.base/java/util/Collection.html)
[`Map`](https://docs.oracle.com/javase/jp/11/docs/api/java.base/java/util/Map.html)
:::


https://qiita.com/T-ngtj/private/df254aacd05be698199a