mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-05 17:37:59 +08:00
MapUtil增加根据entry分组
This commit is contained in:
parent
3965535a2d
commit
508c139b22
@ -23,6 +23,7 @@
|
||||
* 【extra 】 resource.loader等过期参数替换(issue#2571@Github)
|
||||
* 【core 】 添加ObjectUtil的别名工具类ObjUtil
|
||||
* 【core 】 扩展LocalDateTimeUtil.isIn方法使用场景(pr#2589@Github)
|
||||
* 【core 】 MapUtil增加根据entry分组(pr#2591@Github)
|
||||
*
|
||||
### 🐞Bug修复
|
||||
* 【http 】 修复https下可能的Patch、Get请求失效问题(issue#I3Z3DH@Gitee)
|
||||
|
@ -107,7 +107,7 @@ public class MapUtil {
|
||||
* @since 3.0.4
|
||||
*/
|
||||
public static <K, V> HashMap<K, V> newHashMap(int size, boolean isLinked) {
|
||||
int initialCapacity = (int) (size / DEFAULT_LOAD_FACTOR) + 1;
|
||||
final int initialCapacity = (int) (size / DEFAULT_LOAD_FACTOR) + 1;
|
||||
return isLinked ? new LinkedHashMap<>(initialCapacity) : new HashMap<>(initialCapacity);
|
||||
}
|
||||
|
||||
@ -504,19 +504,19 @@ public class MapUtil {
|
||||
* @return entries
|
||||
*/
|
||||
public static <K, V> Map<K, List<V>> grouping(Iterable<Map.Entry<K, V>> entries) {
|
||||
final Map<K, List<V>> map = new HashMap<>(DEFAULT_INITIAL_CAPACITY);
|
||||
final Map<K, List<V>> map = new HashMap<>();
|
||||
if (CollUtil.isEmpty(entries)) {
|
||||
return map;
|
||||
}
|
||||
for (Map.Entry<K, V> pair : entries) {
|
||||
for (final Map.Entry<K, V> pair : entries) {
|
||||
final List<V> values;
|
||||
if (map.containsKey(pair.getKey())) {
|
||||
List<V> values = map.get(pair.getKey());
|
||||
values.add(pair.getValue());
|
||||
values = map.get(pair.getKey());
|
||||
} else {
|
||||
List<V> values = CollUtil.<V>newArrayList();
|
||||
values.add(pair.getValue());
|
||||
values = new ArrayList<>();
|
||||
map.put(pair.getKey(), values);
|
||||
}
|
||||
values.add(pair.getValue());
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user