Java8的stream流中的toMap函数

 @Testpublic void test() {User user = new User();user.setName("123");user.setPassword("123");User user1 = new User();user1.setName("123");user1.setPassword("124");User user2 = new User();user2.setName("124");user2.setPassword("125");User user3 = new User();user3.setName("125");user3.setPassword("125");List<User> users = new ArrayList<>();users.add(user);users.add(user1);users.add(user2);users.add(user3);Map<String, List<User>> userMap = users.stream().collect(Collectors.toMap(User::getName, p -> {List<User> list = new ArrayList<>();list.add(user);return list;}, (List<User> value1, List<User> value2) -> {value1.addAll(value2);return value1;}));System.out.println(userMap.toString());}
}
"C:\Program Files\Java\jdk-11.0.5\bin\java.exe" -ea -Didea.test.cyclic.buffer.size=1048576 "-javaagent:E:\sofe\Idea\IntelliJ IDEA 2019.2.4\lib\idea_rt.jar=63858:E:\sofe\Idea\IntelliJ IDEA 2019.2.4\bin" -Dfile.encoding=UTF-8 -classpath "E:\sofe\Idea\IntelliJ IDEA 2019.2.4\lib\idea_rt.jar;E:\sofe\Idea\IntelliJ IDEA 2019.2.4\plugins\junit\lib\junit-rt.jar;E:\sofe\Idea\IntelliJ IDEA 2019.2.4\plugins\junit\lib\junit5-rt.jar;E:\sofe\maven\maven-repository-20191031\org\junit\platform\junit-platform-launcher\1.5.2\junit-platform-launcher-1.5.2.jar;E:\sofe\maven\maven-repository-20191031\org\apiguardian\apiguardian-api\1.1.0\apiguardian-api-1.1.0.jar;E:\sofe\maven\maven-repository-20191031\org\junit\platform\junit-platform-engine\1.5.2\junit-platform-engine-1.5.2.jar;E:\sofe\maven\maven-repository-20191031\org\opentest4j\opentest4j\1.2.0\opentest4j-1.2.0.jar;E:\sofe\maven\maven-repository-20191031\org\junit\platform\junit-platform-commons\1.5.2\junit-platform-commons-1.5.2.jar;E:\demo\target\test-classes;E:\demo\target\classes;E:\sofe\maven\maven-repository-20191031\org\springframework\boot\spring-boot-starter-security\2.2.2.RELEASE\spring-boot-starter-security-2.2.2.RELEASE.jar;E:\sofe\maven\maven-repository-20191031\org\springframework\boot\spring-boot-starter\2.2.2.RELEASE\spring-boot-starter-2.2.2.RELEASE.jar;E:\sofe\maven\maven-repository-20191031\org\springframework\boot\spring-boot\2.2.2.RELEASE\spring-boot-2.2.2.RELEASE.jar;E:\sofe\maven\maven-repository-20191031\org\springframework\boot\spring-boot-autoconfigure\2.2.2.RELEASE\spring-boot-autoconfigure-2.2.2.RELEASE.jar;E:\sofe\maven\maven-repository-20191031\org\springframework\boot\spring-boot-starter-logging\2.2.2.RELEASE\spring-boot-starter-logging-2.2.2.RELEASE.jar;E:\sofe\maven\maven-repository-20191031\ch\qos\logback\logback-classic\1.2.3\logback-classic-1.2.3.jar;E:\sofe\maven\maven-repository-20191031\ch\qos\logback\logback-core\1.2.3\logback-core-1.2.3.jar;E:\sofe\maven\maven-repository-20191031\org\apache\logging\log4j\log4j-to-slf4j\2.12.1\log4j-to-slf4j-2.12.1.jar;E:\sofe\maven\maven-repository-20191031\org\apache\logging\log4j\log4j-api\2.12.1\log4j-api-2.12.1.jar;E:\sofe\maven\maven-repository-20191031\org\slf4j\jul-to-slf4j\1.7.29\jul-to-slf4j-1.7.29.jar;E:\sofe\maven\maven-repository-20191031\jakarta\annotation\jakarta.annotation-api\1.3.5\jakarta.annotation-api-1.3.5.jar;E:\sofe\maven\maven-repository-20191031\org\yaml\snakeyaml\1.25\snakeyaml-1.25.jar;E:\sofe\maven\maven-repository-20191031\org\springframework\spring-aop\5.2.2.RELEASE\spring-aop-5.2.2.RELEASE.jar;E:\sofe\maven\maven-repository-20191031\org\springframework\spring-beans\5.2.2.RELEASE\spring-beans-5.2.2.RELEASE.jar;E:\sofe\maven\maven-repository-20191031\org\springframework\security\spring-security-config\5.2.1.RELEASE\spring-security-config-5.2.1.RELEASE.jar;E:\sofe\maven\maven-repository-20191031\org\springframework\spring-context\5.2.2.RELEASE\spring-context-5.2.2.RELEASE.jar;E:\sofe\maven\maven-repository-20191031\org\springframework\security\spring-security-web\5.2.1.RELEASE\spring-security-web-5.2.1.RELEASE.jar;E:\sofe\maven\maven-repository-20191031\org\springframework\spring-expression\5.2.2.RELEASE\spring-expression-5.2.2.RELEASE.jar;E:\sofe\maven\maven-repository-20191031\org\springframework\boot\spring-boot-starter-web\2.2.2.RELEASE\spring-boot-starter-web-2.2.2.RELEASE.jar;E:\sofe\maven\maven-repository-20191031\org\springframework\boot\spring-boot-starter-json\2.2.2.RELEASE\spring-boot-starter-json-2.2.2.RELEASE.jar;E:\sofe\maven\maven-repository-20191031\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.10.1\jackson-datatype-jdk8-2.10.1.jar;E:\sofe\maven\maven-repository-20191031\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.10.1\jackson-datatype-jsr310-2.10.1.jar;E:\sofe\maven\maven-repository-20191031\com\fasterxml\jackson\module\jackson-module-parameter-names\2.10.1\jackson-module-parameter-names-2.10.1.jar;E:\sofe\maven\maven-repository-20191031\org\springframework\boot\spring-boot-starter-tomcat\2.2.2.RELEASE\spring-boot-starter-tomcat-2.2.2.RELEASE.jar;E:\sofe\maven\maven-repository-20191031\org\apache\tomcat\embed\tomcat-embed-core\9.0.29\tomcat-embed-core-9.0.29.jar;E:\sofe\maven\maven-repository-20191031\org\apache\tomcat\embed\tomcat-embed-el\9.0.29\tomcat-embed-el-9.0.29.jar;E:\sofe\maven\maven-repository-20191031\org\apache\tomcat\embed\tomcat-embed-websocket\9.0.29\tomcat-embed-websocket-9.0.29.jar;E:\sofe\maven\maven-repository-20191031\org\springframework\boot\spring-boot-starter-validation\2.2.2.RELEASE\spring-boot-starter-validation-2.2.2.RELEASE.jar;E:\sofe\maven\maven-repository-20191031\jakarta\validation\jakarta.validation-api\2.0.1\jakarta.validation-api-2.0.1.jar;E:\sofe\maven\maven-repository-20191031\org\hibernate\validator\hibernate-validator\6.0.18.Final\hibernate-validator-6.0.18.Final.jar;E:\sofe\maven\maven-repository-20191031\org\jboss\logging\jboss-logging\3.4.1.Final\jboss-logging-3.4.1.Final.jar;E:\sofe\maven\maven-repository-20191031\com\fasterxml\classmate\1.5.1\classmate-1.5.1.jar;E:\sofe\maven\maven-repository-20191031\org\springframework\spring-web\5.2.2.RELEASE\spring-web-5.2.2.RELEASE.jar;E:\sofe\maven\maven-repository-20191031\org\springframework\spring-webmvc\5.2.2.RELEASE\spring-webmvc-5.2.2.RELEASE.jar;E:\sofe\maven\maven-repository-20191031\org\mybatis\spring\boot\mybatis-spring-boot-starter\2.1.1\mybatis-spring-boot-starter-2.1.1.jar;E:\sofe\maven\maven-repository-20191031\org\springframework\boot\spring-boot-starter-jdbc\2.2.2.RELEASE\spring-boot-starter-jdbc-2.2.2.RELEASE.jar;E:\sofe\maven\maven-repository-20191031\com\zaxxer\HikariCP\3.4.1\HikariCP-3.4.1.jar;E:\sofe\maven\maven-repository-20191031\org\springframework\spring-jdbc\5.2.2.RELEASE\spring-jdbc-5.2.2.RELEASE.jar;E:\sofe\maven\maven-repository-20191031\org\mybatis\spring\boot\mybatis-spring-boot-autoconfigure\2.1.1\mybatis-spring-boot-autoconfigure-2.1.1.jar;E:\sofe\maven\maven-repository-20191031\org\mybatis\mybatis\3.5.3\mybatis-3.5.3.jar;E:\sofe\maven\maven-repository-20191031\org\mybatis\mybatis-spring\2.0.3\mybatis-spring-2.0.3.jar;E:\sofe\maven\maven-repository-20191031\org\projectlombok\lombok\1.18.10\lombok-1.18.10.jar;E:\sofe\maven\maven-repository-20191031\org\springframework\boot\spring-boot-starter-test\2.2.2.RELEASE\spring-boot-starter-test-2.2.2.RELEASE.jar;E:\sofe\maven\maven-repository-20191031\org\springframework\boot\spring-boot-test\2.2.2.RELEASE\spring-boot-test-2.2.2.RELEASE.jar;E:\sofe\maven\maven-repository-20191031\org\springframework\boot\spring-boot-test-autoconfigure\2.2.2.RELEASE\spring-boot-test-autoconfigure-2.2.2.RELEASE.jar;E:\sofe\maven\maven-repository-20191031\com\jayway\jsonpath\json-path\2.4.0\json-path-2.4.0.jar;E:\sofe\maven\maven-repository-20191031\net\minidev\json-smart\2.3\json-smart-2.3.jar;E:\sofe\maven\maven-repository-20191031\net\minidev\accessors-smart\1.2\accessors-smart-1.2.jar;E:\sofe\maven\maven-repository-20191031\org\ow2\asm\asm\5.0.4\asm-5.0.4.jar;E:\sofe\maven\maven-repository-20191031\org\slf4j\slf4j-api\1.7.29\slf4j-api-1.7.29.jar;E:\sofe\maven\maven-repository-20191031\jakarta\xml\bind\jakarta.xml.bind-api\2.3.2\jakarta.xml.bind-api-2.3.2.jar;E:\sofe\maven\maven-repository-20191031\jakarta\activation\jakarta.activation-api\1.2.1\jakarta.activation-api-1.2.1.jar;E:\sofe\maven\maven-repository-20191031\org\junit\jupiter\junit-jupiter\5.5.2\junit-jupiter-5.5.2.jar;E:\sofe\maven\maven-repository-20191031\org\junit\jupiter\junit-jupiter-api\5.5.2\junit-jupiter-api-5.5.2.jar;E:\sofe\maven\maven-repository-20191031\org\junit\jupiter\junit-jupiter-params\5.5.2\junit-jupiter-params-5.5.2.jar;E:\sofe\maven\maven-repository-20191031\org\junit\jupiter\junit-jupiter-engine\5.5.2\junit-jupiter-engine-5.5.2.jar;E:\sofe\maven\maven-repository-20191031\org\mockito\mockito-junit-jupiter\3.1.0\mockito-junit-jupiter-3.1.0.jar;E:\sofe\maven\maven-repository-20191031\org\assertj\assertj-core\3.13.2\assertj-core-3.13.2.jar;E:\sofe\maven\maven-repository-20191031\org\hamcrest\hamcrest\2.1\hamcrest-2.1.jar;E:\sofe\maven\maven-repository-20191031\org\mockito\mockito-core\3.1.0\mockito-core-3.1.0.jar;E:\sofe\maven\maven-repository-20191031\net\bytebuddy\byte-buddy\1.10.4\byte-buddy-1.10.4.jar;E:\sofe\maven\maven-repository-20191031\net\bytebuddy\byte-buddy-agent\1.10.4\byte-buddy-agent-1.10.4.jar;E:\sofe\maven\maven-repository-20191031\org\objenesis\objenesis\2.6\objenesis-2.6.jar;E:\sofe\maven\maven-repository-20191031\org\skyscreamer\jsonassert\1.5.0\jsonassert-1.5.0.jar;E:\sofe\maven\maven-repository-20191031\com\vaadin\external\google\android-json\0.0.20131108.vaadin1\android-json-0.0.20131108.vaadin1.jar;E:\sofe\maven\maven-repository-20191031\org\springframework\spring-core\5.2.2.RELEASE\spring-core-5.2.2.RELEASE.jar;E:\sofe\maven\maven-repository-20191031\org\springframework\spring-jcl\5.2.2.RELEASE\spring-jcl-5.2.2.RELEASE.jar;E:\sofe\maven\maven-repository-20191031\org\springframework\spring-test\5.2.2.RELEASE\spring-test-5.2.2.RELEASE.jar;E:\sofe\maven\maven-repository-20191031\org\xmlunit\xmlunit-core\2.6.3\xmlunit-core-2.6.3.jar;E:\sofe\maven\maven-repository-20191031\org\springframework\security\spring-security-test\5.2.1.RELEASE\spring-security-test-5.2.1.RELEASE.jar;E:\sofe\maven\maven-repository-20191031\org\springframework\security\spring-security-core\5.2.1.RELEASE\spring-security-core-5.2.1.RELEASE.jar;E:\sofe\maven\maven-repository-20191031\mysql\mysql-connector-java\6.0.5\mysql-connector-java-6.0.5.jar;E:\sofe\maven\maven-repository-20191031\com\alibaba\druid\1.1.12\druid-1.1.12.jar;E:\sofe\maven\maven-repository-20191031\org\springframework\boot\spring-boot-starter-data-redis\2.2.2.RELEASE\spring-boot-starter-data-redis-2.2.2.RELEASE.jar;E:\sofe\maven\maven-repository-20191031\org\springframework\data\spring-data-redis\2.2.3.RELEASE\spring-data-redis-2.2.3.RELEASE.jar;E:\sofe\maven\maven-repository-20191031\org\springframework\data\spring-data-keyvalue\2.2.3.RELEASE\spring-data-keyvalue-2.2.3.RELEASE.jar;E:\sofe\maven\maven-repository-20191031\org\springframework\data\spring-data-commons\2.2.3.RELEASE\spring-data-commons-2.2.3.RELEASE.jar;E:\sofe\maven\maven-repository-20191031\org\springframework\spring-tx\5.2.2.RELEASE\spring-tx-5.2.2.RELEASE.jar;E:\sofe\maven\maven-repository-20191031\org\springframework\spring-oxm\5.2.2.RELEASE\spring-oxm-5.2.2.RELEASE.jar;E:\sofe\maven\maven-repository-20191031\org\springframework\spring-context-support\5.2.2.RELEASE\spring-context-support-5.2.2.RELEASE.jar;E:\sofe\maven\maven-repository-20191031\io\lettuce\lettuce-core\5.2.1.RELEASE\lettuce-core-5.2.1.RELEASE.jar;E:\sofe\maven\maven-repository-20191031\io\netty\netty-common\4.1.43.Final\netty-common-4.1.43.Final.jar;E:\sofe\maven\maven-repository-20191031\io\netty\netty-handler\4.1.43.Final\netty-handler-4.1.43.Final.jar;E:\sofe\maven\maven-repository-20191031\io\netty\netty-buffer\4.1.43.Final\netty-buffer-4.1.43.Final.jar;E:\sofe\maven\maven-repository-20191031\io\netty\netty-codec\4.1.43.Final\netty-codec-4.1.43.Final.jar;E:\sofe\maven\maven-repository-20191031\io\netty\netty-transport\4.1.43.Final\netty-transport-4.1.43.Final.jar;E:\sofe\maven\maven-repository-20191031\io\netty\netty-resolver\4.1.43.Final\netty-resolver-4.1.43.Final.jar;E:\sofe\maven\maven-repository-20191031\io\projectreactor\reactor-core\3.3.1.RELEASE\reactor-core-3.3.1.RELEASE.jar;E:\sofe\maven\maven-repository-20191031\org\reactivestreams\reactive-streams\1.0.3\reactive-streams-1.0.3.jar;E:\sofe\maven\maven-repository-20191031\cn\hutool\hutool-all\4.3.1\hutool-all-4.3.1.jar;E:\sofe\maven\maven-repository-20191031\io\jsonwebtoken\jjwt\0.7.0\jjwt-0.7.0.jar;E:\sofe\maven\maven-repository-20191031\com\fasterxml\jackson\core\jackson-databind\2.10.1\jackson-databind-2.10.1.jar;E:\sofe\maven\maven-repository-20191031\com\fasterxml\jackson\core\jackson-annotations\2.10.1\jackson-annotations-2.10.1.jar;E:\sofe\maven\maven-repository-20191031\com\fasterxml\jackson\core\jackson-core\2.10.1\jackson-core-2.10.1.jar;E:\sofe\maven\maven-repository-20191031\org\apache\commons\commons-pool2\2.7.0\commons-pool2-2.7.0.jar;E:\sofe\maven\maven-repository-20191031\javax\xml\bind\jaxb-api\2.3.0\jaxb-api-2.3.0.jar;E:\sofe\maven\maven-repository-20191031\com\sun\xml\bind\jaxb-impl\2.3.0\jaxb-impl-2.3.0.jar;E:\sofe\maven\maven-repository-20191031\com\sun\xml\bind\jaxb-core\2.3.0\jaxb-core-2.3.0.jar;E:\sofe\maven\maven-repository-20191031\javax\activation\activation\1.1.1\activation-1.1.1.jar;E:\sofe\maven\maven-repository-20191031\org\apache\poi\poi-ooxml\4.1.0\poi-ooxml-4.1.0.jar;E:\sofe\maven\maven-repository-20191031\org\apache\poi\poi\4.1.0\poi-4.1.0.jar;E:\sofe\maven\maven-repository-20191031\commons-codec\commons-codec\1.13\commons-codec-1.13.jar;E:\sofe\maven\maven-repository-20191031\org\apache\commons\commons-collections4\4.3\commons-collections4-4.3.jar;E:\sofe\maven\maven-repository-20191031\org\apache\commons\commons-math3\3.6.1\commons-math3-3.6.1.jar;E:\sofe\maven\maven-repository-20191031\org\apache\poi\poi-ooxml-schemas\4.1.0\poi-ooxml-schemas-4.1.0.jar;E:\sofe\maven\maven-repository-20191031\org\apache\xmlbeans\xmlbeans\3.1.0\xmlbeans-3.1.0.jar;E:\sofe\maven\maven-repository-20191031\org\apache\commons\commons-compress\1.18\commons-compress-1.18.jar;E:\sofe\maven\maven-repository-20191031\com\github\virtuald\curvesapi\1.06\curvesapi-1.06.jar" com.intellij.rt.execution.junit.JUnitStarter -ideVersion5 -junit5 com.example.demo.mapper.UserMapperTest,test
10:34:11.101 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating CacheAwareContextLoaderDelegate from class [org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate]
10:34:11.116 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating BootstrapContext using constructor [public org.springframework.test.context.support.DefaultBootstrapContext(java.lang.Class,org.springframework.test.context.CacheAwareContextLoaderDelegate)]
10:34:11.148 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating TestContextBootstrapper for test class [com.example.demo.mapper.UserMapperTest] from class [org.springframework.boot.test.context.SpringBootTestContextBootstrapper]
10:34:11.167 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Neither @ContextConfiguration nor @ContextHierarchy found for test class [com.example.demo.mapper.UserMapperTest], using SpringBootContextLoader
10:34:11.174 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [com.example.demo.mapper.UserMapperTest]: class path resource [com/example/demo/mapper/UserMapperTest-context.xml] does not exist
10:34:11.175 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [com.example.demo.mapper.UserMapperTest]: class path resource [com/example/demo/mapper/UserMapperTestContext.groovy] does not exist
10:34:11.175 [main] INFO org.springframework.test.context.support.AbstractContextLoader - Could not detect default resource locations for test class [com.example.demo.mapper.UserMapperTest]: no resource found for suffixes {-context.xml, Context.groovy}.
10:34:11.176 [main] INFO org.springframework.test.context.support.AnnotationConfigContextLoaderUtils - Could not detect default configuration classes for test class [com.example.demo.mapper.UserMapperTest]: UserMapperTest does not declare any static, non-private, non-final, nested classes annotated with @Configuration.
10:34:11.235 [main] DEBUG org.springframework.test.context.support.ActiveProfilesUtils - Could not find an 'annotation declaring class' for annotation type [org.springframework.test.context.ActiveProfiles] and class [com.example.demo.mapper.UserMapperTest]
10:34:11.345 [main] DEBUG org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider - Identified candidate component class: file [E:\demo\target\classes\com\example\demo\SimpleApplication.class]
10:34:11.346 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Found @SpringBootConfiguration com.example.demo.SimpleApplication for test class com.example.demo.mapper.UserMapperTest
10:34:11.487 [main] DEBUG org.springframework.boot.test.context.SpringBootTestContextBootstrapper - @TestExecutionListeners is not present for class [com.example.demo.mapper.UserMapperTest]: using defaults.
10:34:11.487 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener, org.springframework.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener, org.springframework.test.context.support.DependencyInjectionTestExecutionListener, org.springframework.test.context.support.DirtiesContextTestExecutionListener, org.springframework.test.context.transaction.TransactionalTestExecutionListener, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener, org.springframework.test.context.event.EventPublishingTestExecutionListener, org.springframework.security.test.context.support.WithSecurityContextTestExecutionListener, org.springframework.security.test.context.support.ReactorContextTestExecutionListener]
10:34:11.512 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Using TestExecutionListeners: [org.springframework.test.context.web.ServletTestExecutionListener@5d8bafa9, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@576f63f6, org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener@2dca0d64, org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener@f80945f, org.springframework.test.context.support.DirtiesContextTestExecutionListener@ff684e1, org.springframework.test.context.transaction.TransactionalTestExecutionListener@23aa363a, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener@5ef6ae06, org.springframework.test.context.event.EventPublishingTestExecutionListener@55dfebeb, org.springframework.security.test.context.support.WithSecurityContextTestExecutionListener@6e35bc3d, org.springframework.security.test.context.support.ReactorContextTestExecutionListener@1cdc4c27, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener@77b14724, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener@5d9b7a8a, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener@1e8ce150, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener@604f2bd2, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener@1d3ac898]
10:34:11.517 [main] DEBUG org.springframework.test.context.support.AbstractDirtiesContextTestExecutionListener - Before test class: context [DefaultTestContext@1ecee32c testClass = UserMapperTest, testInstance = [null], testMethod = [null], testException = [null], mergedContextConfiguration = [WebMergedContextConfiguration@4372b9b6 testClass = UserMapperTest, locations = '{}', classes = '{class com.example.demo.SimpleApplication}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true}', contextCustomizers = set[org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@6a8658ff, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@55de24cc, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@821330f, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@14dd7b39], resourceBasePath = 'src/main/webapp', contextLoader = 'org.springframework.boot.test.context.SpringBootContextLoader', parent = [null]], attributes = map['org.springframework.test.context.web.ServletTestExecutionListener.activateListener' -> true]], class annotated with @DirtiesContext [false] with mode [null].
10:34:11.560 [main] DEBUG org.springframework.test.context.support.TestPropertySourceUtils - Adding inlined properties to environment: {spring.jmx.enabled=false, org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true, server.port=-1}.   ____          _            __ _ _/\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \\\/  ___)| |_)| | | | | || (_| |  ) ) ) )'  |____| .__|_| |_|_| |_\__, | / / / /=========|_|==============|___/=/_/_/_/:: Spring Boot ::        (v2.2.2.RELEASE)2019-12-17 10:34:12.076  INFO 87840 --- [           main] com.example.demo.mapper.UserMapperTest   : Starting UserMapperTest on LAPTOP-5L33IHOU with PID 87840 (started by Lenovo in E:\demo)
2019-12-17 10:34:12.078 DEBUG 87840 --- [           main] com.example.demo.mapper.UserMapperTest   : Running with Spring Boot v2.2.2.RELEASE, Spring v5.2.2.RELEASE
2019-12-17 10:34:12.079  INFO 87840 --- [           main] com.example.demo.mapper.UserMapperTest   : No active profile set, falling back to default profiles: default
2019-12-17 10:34:13.309  INFO 87840 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode!
2019-12-17 10:34:13.313  INFO 87840 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data Redis repositories in DEFAULT mode.
2019-12-17 10:34:13.361  INFO 87840 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 23ms. Found 0 Redis repository interfaces.
2019-12-17 10:34:14.041  INFO 87840 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-12-17 10:34:18.143  INFO 87840 --- [           main] o.s.s.web.DefaultSecurityFilterChain     : Creating filter chain: any request, [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@40d96578, org.springframework.security.web.context.SecurityContextPersistenceFilter@19f02280, org.springframework.security.web.header.HeaderWriterFilter@28a6e171, org.springframework.web.filter.CorsFilter@c97721b, org.springframework.security.web.authentication.logout.LogoutFilter@5d9618f2, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@cc9ef8d, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@fbe70d8, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@283ab206, org.springframework.security.web.session.SessionManagementFilter@265c1a7c, org.springframework.security.web.access.ExceptionTranslationFilter@1472208d, org.springframework.security.web.access.intercept.FilterSecurityInterceptor@359ceb13]
2019-12-17 10:34:18.217 ERROR 87840 --- [           main] o.a.catalina.core.AprLifecycleListener   : An incompatible version [1.2.8] of the APR based Apache Tomcat Native library is installed, while Tomcat requires version [1.2.14]
2019-12-17 10:34:18.527  INFO 87840 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2019-12-17 10:34:19.467  INFO 87840 --- [           main] com.example.demo.mapper.UserMapperTest   : Started UserMapperTest in 7.894 seconds (JVM running for 9.218){123=[User(id=null, password=123, name=123, createTime=null, updateTime=null, role=null), User(id=null, password=123, name=123, createTime=null, updateTime=null, role=null)], 124=[User(id=null, password=123, name=123, createTime=null, updateTime=null, role=null)], 125=[User(id=null, password=123, name=123, createTime=null, updateTime=null, role=null)]}2019-12-17 10:34:19.990  INFO 87840 --- [extShutdownHook] o.s.s.concurrent.ThreadPoolTaskExecutor  : Shutting down ExecutorService 'applicationTaskExecutor'Process finished with exit code 0

list 转化为map出现key重复:

 @Testpublic void testList() {User user = new User();user.setName("123");user.setPassword("123");User user1 = new User();user1.setName("123");user1.setPassword("124");User user2 = new User();user2.setName("124");user2.setPassword("125");User user3 = new User();user3.setName("125");user3.setPassword("125");List<User> users = new ArrayList<>();users.add(user);users.add(user1);users.add(user2);users.add(user3);Map<String, String> userMap = users.stream().collect(Collectors.toMap(User::getName, User::getPassword));System.out.println(userMap);}
java.lang.IllegalStateException: Duplicate key 123 (attempted merging values 123 and 124)at java.base/java.util.stream.Collectors.duplicateKeyException(Collectors.java:133)at java.base/java.util.stream.Collectors.lambda$uniqKeysMapAccumulator$1(Collectors.java:180)at java.base/java.util.stream.ReduceOps$3ReducingSink.accept(ReduceOps.java:169)at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1654)at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:913)at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:578)at com.example.demo.mapper.UserMapperTest.testList(UserMapperTest.java:183)at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)at java.base/java.lang.reflect.Method.invoke(Method.java:566)at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:675)at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:125)at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:132)at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:124)at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:74)at org.junit.jupiter.engine.execution.ExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(ExecutableInvoker.java:115)at org.junit.jupiter.engine.execution.ExecutableInvoker.lambda$invoke$0(ExecutableInvoker.java:105)at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:104)at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:62)at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:43)at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:35)at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:104)at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:98)at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$6(TestMethodTestDescriptor.java:202)at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:198)at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:135)at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:69)at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:135)at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)at java.base/java.util.ArrayList.forEach(ArrayList.java:1540)at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139)at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)at java.base/java.util.ArrayList.forEach(ArrayList.java:1540)at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139)at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:32)at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:51)at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:229)at org.junit.platform.launcher.core.DefaultLauncher.lambda$execute$6(DefaultLauncher.java:197)at org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStreams(DefaultLauncher.java:211)at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:191)at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:128)at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:69)at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

解决:1.将后面的值覆盖前面的值

 Map<String, String> userMap = users.stream().collect(Collectors.toMap(User::getName, User::getPassword, (String name1, String name2) -> name2));System.out.println(userMap);

{123=124, 124=125, 125=125}2019-12-17 15:15:18.432  INFO 98828 --- [extShutdownHook] o.s.s.concurrent.ThreadPoolTaskExecutor  : Shutting down ExecutorService 'applicationTaskExecutor'Process finished with exit code 0

2.将重复值拼接后返回

Map<String, String> userMap = users.stream().collect(Collectors.toMap(User::getName, User::getPassword, (String name1, String name2) -> name1 + ":" + name2));System.out.println(userMap);
{123=123:124, 124=125, 125=125}2019-12-17 15:19:39.014  INFO 94772 --- [extShutdownHook] o.s.s.concurrent.ThreadPoolTaskExecutor  : Shutting down ExecutorService 'applicationTaskExecutor'Process finished with exit code 0

3.将重复的值返回成集合

Map<String, List<String>> userMap = users.stream().collect(Collectors.toMap(User::getName, perUser -> {List<String> list = new ArrayList<>();list.add(perUser.getPassword());return list;},(List<String> password1, List<String> password2) -> {password1.addAll(password2);return password1;}));System.out.println(userMap);

{123=[123, 124], 124=[125], 125=[125]}2019-12-17 15:40:05.683  INFO 101176 --- [extShutdownHook] o.s.s.concurrent.ThreadPoolTaskExecutor  : Shutting down ExecutorService 'applicationTaskExecutor'Process finished with exit code 0

有兴趣学习的可以关注公众号阅读相关:码上行走

toMap函数 java.lang.IllegalStateException: Duplicate key 123 (attempted merging values 123 and 124)相关推荐

  1. JDK8 stream toMap() java.lang.IllegalStateException: Duplicate key异常解决(key重复)

    测试又报bug啦 接到测试小伙伴的问题,说是一个接口不返回数据了,好吧,虽然不是我写的接口任务落到头上也得解决,本地调试了一下,好家伙,直接抛了个异常出来,这又是哪位大哥喝醉了写的代码... Exce ...

  2. java.lang.IllegalStateException: Duplicate key 【java8 toMap(key重复如何解决)】

    使用stream的toMap()函数时,当key重复,系统会报错相同的key不能形成一个map,那么需要解决这个问题, 1.首先查看库中数据结构,相同人员编号存在多条关键词(arr_gic) List ...

  3. Exception in thread “main“ java.lang.IllegalStateException: Duplicate key xxx

    debug.. hah- 这个错误是使用stream流把list收集成map搞的,原因是map的key是唯一的,如果不唯一就抛出了这个异常. 下面是异常代码 import java.util.Arra ...

  4. 错误记录:java.lang.IllegalStateException:Duplicate key

    原因 Map中出现了和被转换的List中重复的key记录 try {//发起远程请求R skuHasStock = wareFeignService.getSkusHasStock(skuIds);/ ...

  5. 报错Caused by: java.lang.IllegalStateException: duplicate key: spring

    以上截图是我使用git重复提交5次的结果,第五次提交成功:这个故事告诉我们:当你连续犯好几次错的时候,你离成功就不远了~~~(其实也就是个小问题,yml里面格式的问题~) 1.当我们需要在同一个yml ...

  6. ElasticSearch出现java.lang.IllegalStateException: duplicate plugin: - Plugin information:

    为了使用IK-中文分词器,特地去下载了一个,结果重启动ES之后,进入Kibana可视化界面,出现了503服务不可用:一开始以为是Kibana还没注册进ES中,结果等待了一会还是如此. 1.使用dock ...

  7. viewpager2异常: java.lang.IllegalStateException: Fragment no longer exists for key f#1: unique id 8052

    异常信息: java.lang.IllegalStateException: Fragment no longer exists for key f#1: unique id 805285bc-7a1 ...

  8. 订阅者java_RxJava:“java.lang.IllegalStateException:只允许一个订阅者!”

    我正在使用RxJava来计算Android中某些传感器数据的标准化自动关联 . 奇怪的是,我的代码抛出一个异常("java.lang.IllegalStateException:只允许一个订 ...

  9. 解决java.lang.IllegalStateException: getOutputStream() has already been called for this response

    简单的说:用了流之后关掉即可. 下面详细说明: 出现了java.lang.IllegalStateException: getOutputStream() has already been calle ...

  10. java.lang.IllegalStateException: 启动子级时出错

    java.lang.IllegalStateException: 启动子级时出错 at org.apache.catalina.core.ContainerBase.addChildInternal( ...

最新文章

  1. 心系AI的百度,这次能翻身吗?
  2. 设计师电脑推荐笔记本_笔记本电脑选购推荐全攻略
  3. java dump分析工具_Java虚拟机详解(七)------虚拟机监控和分析工具(1)
  4. android view setleft,android – 在新textview上使用setLeft / setRight方法
  5. LeetCode 674. 最长连续递增序列 (滑动窗口 计数法)
  6. java的各种加载和初始化的详细过程
  7. 解决Nginx + PHP(FastCGI)遇到的502 Bad Gateway错误[原创]
  8. 处女作:《游戏AI程序设计实战》2019.4.1
  9. JAVA毕业设计Web企业差旅在线管理系统计算机源码+lw文档+系统+调试部署+数据库
  10. 双边滤波器和高斯滤波器
  11. window7修改屏幕旋转快捷键
  12. Effective C++学习笔记(条款1-34)
  13. 计算机学报编辑待遇,《计算机学报》编辑委员会
  14. 第10章:项目沟通管理和干系人管理-章节真题
  15. 系统等保指的是信息系统的安全保护等级
  16. 嵌入式Linux 3G pppd拨号上网问题
  17. Domino版本、维护版本和补丁程序概念
  18. python+opencv+图像特效(图像灰度处理、颜色翻转、图片融合,边缘检测,浮雕效果,颜色映射)
  19. 大彩科技新品首发--新1代HMI人机界面!
  20. cass10.1+鸿业生成平纵横数据

热门文章

  1. 企业信息系统集成发展阶段及ESB对企业的价值体现
  2. 您的php似乎没有安装运行wordpress所必需的mysql扩展_“您的 PHP 似乎没有安装运行 WordPress 所必需的 MySQL 扩展”处理方法...
  3. 进出口业务财务一体化外贸流程管理解决方案
  4. c语言else的用法,else的用法
  5. 全国哀悼日,网站变黑白完美兼容IE,亲测有效
  6. 网络学习笔记之路由器基本命令行操作
  7. c语言 求圆周长 圆面积 圆球表面积 圆球体积 圆柱体积
  8. try的动词用法_try的用法_tries与try的用法,请分别举例说明。谢!
  9. asp mysql rs.recordcount_asp 中rs.fields.count,rs.recordcount代表什么意思
  10. 信息安全概论课堂笔记