This commit is contained in:
Looly
2021-10-09 21:13:30 +08:00
parent 0f96a95f2c
commit 412160ac53
4 changed files with 57 additions and 1 deletions

View File

@@ -712,6 +712,23 @@ public class CollUtilTest {
Assert.assertEquals("d", map.get("keyd"));
}
@Test
public void mapToMapTest(){
final HashMap<String, String> oldMap = new HashMap<>();
oldMap.put("a", "1");
oldMap.put("b", "12");
oldMap.put("c", "134");
final Map<String, Long> map = CollUtil.toMap(oldMap.entrySet(),
new HashMap<>(),
Map.Entry::getKey,
entry -> Long.parseLong(entry.getValue()));
Assert.assertEquals(1L, (long)map.get("a"));
Assert.assertEquals(12L, (long)map.get("b"));
Assert.assertEquals(134L, (long)map.get("c"));
}
@Test
public void countMapTest() {
ArrayList<String> list = CollUtil.newArrayList("a", "b", "c", "c", "a", "b", "d");