diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/http/HttpMessageConvertersTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/http/HttpMessageConvertersTests.java index 3f1e119871..1325fdbfa6 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/http/HttpMessageConvertersTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/http/HttpMessageConvertersTests.java @@ -18,7 +18,6 @@ package org.springframework.boot.autoconfigure.http; import java.util.ArrayList; import java.util.Collection; -import java.util.Iterator; import java.util.List; import org.junit.Test; @@ -114,13 +113,8 @@ public class HttpMessageConvertersTests { @Override protected List> postProcessConverters( List> converters) { - for (Iterator> iterator = converters - .iterator(); iterator.hasNext();) { - if (iterator - .next() instanceof MappingJackson2XmlHttpMessageConverter) { - iterator.remove(); - } - } + converters.removeIf( + converter -> converter instanceof MappingJackson2XmlHttpMessageConverter); return converters; } }; @@ -144,13 +138,8 @@ public class HttpMessageConvertersTests { @Override protected List> postProcessPartConverters( List> converters) { - for (Iterator> iterator = converters - .iterator(); iterator.hasNext();) { - if (iterator - .next() instanceof MappingJackson2XmlHttpMessageConverter) { - iterator.remove(); - } - } + converters.removeIf( + converter -> converter instanceof MappingJackson2XmlHttpMessageConverter); return converters; } }; diff --git a/spring-boot-test/src/main/java/org/springframework/boot/test/mock/mockito/MockitoPostProcessor.java b/spring-boot-test/src/main/java/org/springframework/boot/test/mock/mockito/MockitoPostProcessor.java index 5022867233..fc1ed7d71e 100644 --- a/spring-boot-test/src/main/java/org/springframework/boot/test/mock/mockito/MockitoPostProcessor.java +++ b/spring-boot-test/src/main/java/org/springframework/boot/test/mock/mockito/MockitoPostProcessor.java @@ -20,7 +20,6 @@ import java.beans.PropertyDescriptor; import java.lang.reflect.Field; import java.util.Arrays; import java.util.HashMap; -import java.util.Iterator; import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.Map; @@ -280,11 +279,7 @@ public class MockitoPostProcessor extends InstantiationAwareBeanPostProcessorAda beans.add(beanName); } } - for (Iterator iterator = beans.iterator(); iterator.hasNext();) { - if (isScopedTarget(iterator.next())) { - iterator.remove(); - } - } + beans.removeIf(this::isScopedTarget); return beans.toArray(new String[beans.size()]); } diff --git a/spring-boot-test/src/main/java/org/springframework/boot/test/web/client/TestRestTemplate.java b/spring-boot-test/src/main/java/org/springframework/boot/test/web/client/TestRestTemplate.java index 09059acc41..39afe88243 100644 --- a/spring-boot-test/src/main/java/org/springframework/boot/test/web/client/TestRestTemplate.java +++ b/spring-boot-test/src/main/java/org/springframework/boot/test/web/client/TestRestTemplate.java @@ -22,7 +22,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; @@ -149,12 +148,8 @@ public class TestRestTemplate { interceptors = Collections.emptyList(); } interceptors = new ArrayList<>(interceptors); - Iterator iterator = interceptors.iterator(); - while (iterator.hasNext()) { - if (iterator.next() instanceof BasicAuthorizationInterceptor) { - iterator.remove(); - } - } + interceptors.removeIf( + interceptor -> interceptor instanceof BasicAuthorizationInterceptor); interceptors.add(new BasicAuthorizationInterceptor(username, password)); restTemplate.setInterceptors(interceptors); } diff --git a/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/metadata/ConfigurationMetadata.java b/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/metadata/ConfigurationMetadata.java index 7a3bdaa6c0..621e3c17c2 100644 --- a/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/metadata/ConfigurationMetadata.java +++ b/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/metadata/ConfigurationMetadata.java @@ -22,7 +22,6 @@ import java.util.Collections; import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; -import java.util.ListIterator; import java.util.Map; import java.util.Set; @@ -149,12 +148,7 @@ public class ConfigurationMetadata { if (candidates == null || candidates.isEmpty()) { return null; } - ListIterator it = candidates.listIterator(); - while (it.hasNext()) { - if (!it.next().hasSameType(metadata)) { - it.remove(); - } - } + candidates.removeIf(itemMetadata -> !itemMetadata.hasSameType(metadata)); if (candidates.size() == 1) { return candidates.get(0); } diff --git a/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java b/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java index eca02c637d..0b1e839859 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java +++ b/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java @@ -20,7 +20,6 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; -import java.util.Iterator; import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.LinkedList; @@ -530,12 +529,7 @@ public class ConfigFileApplicationListener } private void removeUnprocessedDefaultProfiles() { - for (Iterator iterator = this.profiles.iterator(); iterator - .hasNext();) { - if (iterator.next().isDefaultProfile()) { - iterator.remove(); - } - } + this.profiles.removeIf(Profile::isDefaultProfile); } private void addProfiles(Set profiles) {