UtilsTest.java 文件源码

java
阅读 37 收藏 0 点赞 0 评论 0

项目:LifecycleAware 作者:
@Test
public void testDistinctByKey() throws Exception {
    List<TestPair> testPairList =
            ImmutableList.of(
                    new TestPair("a", "1"),
                    new TestPair("a", "2"),
                    new TestPair("a", "3"),
                    new TestPair("b", "1")
            );

    List<TestPair> distinctByFirst = testPairList.stream()
            .filter(Utils.distinctByKey(testPair -> testPair.first))
            .collect(Collectors.toList());

    Assert.assertNotEquals(testPairList, distinctByFirst);
    Assert.assertEquals(2, distinctByFirst.size());
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号