public final class MapUtil extends Object
| 限定符和类型 | 方法和说明 |
|---|---|
static Map.Entry<String,Object> |
getFirstEntry(Map<String,Object> map)
获取 map 的第一个值
|
static <K,V> V |
getMapValue(Map<K,V> map,
K key,
V defaultValue)
获取对应的映射信息
1.
|
static String |
getMapValue(Map<String,String> map,
String key)
获取对应的映射信息
(1)如果对应的值不存在,则返回 key 本身
(2)如果 map 为空,则返回
|
static boolean |
isEmpty(Map<?,?> map)
判断map为空
|
static boolean |
isNotEmpty(Map<?,?> map)
判断map为非空
|
static <T> void |
putToListMap(Map<String,List<T>> listMap,
String key,
T elem)
元素放置到 map 中
|
static <T> void |
putToSetMap(Map<String,Set<T>> setMap,
String key,
T elem)
元素放置到 map 中
|
static <V> Map<Integer,V> |
toIndexMap(Collection<V> values)
key 是元素的索引
|
static <K,V,T> List<T> |
toList(Map<K,V> map,
IMapEntryHandler<K,V,T> entryHandler)
可遍历的结合转换为 map
|
static <K,V,O> Map<K,V> |
toMap(Collection<O> values,
IMapHandler<K,V,O> mapHandler)
可遍历的结合转换为 map
|
static <K,V> Map<K,V> |
toMap(Collection<V> values,
IHandler<? super V,K> keyFunction)
可遍历的结合转换为 map
|
public static boolean isEmpty(Map<?,?> map)
map - maptrue 为空public static boolean isNotEmpty(Map<?,?> map)
map - maptrue 非空public static <K,V> Map<K,V> toMap(Collection<V> values, IHandler<? super V,K> keyFunction)
K - key 泛型V - value 泛型values - 可遍历的元素 IteratorkeyFunction - 转化方式public static <K,V,O> Map<K,V> toMap(Collection<O> values, IMapHandler<K,V,O> mapHandler)
K - key 泛型V - value 泛型O - 原始泛型values - 可遍历的元素 IteratormapHandler - map 转化方式public static <K,V,T> List<T> toList(Map<K,V> map, IMapEntryHandler<K,V,T> entryHandler)
K - key 泛型V - value 泛型T - 目标泛型map - 可遍历的元素 IteratorentryHandler - entry 转化方式public static <V> Map<Integer,V> toIndexMap(Collection<V> values)
V - 元素泛型values - 值public static String getMapValue(Map<String,String> map, String key)
map - mapkey - keypublic static <K,V> V getMapValue(Map<K,V> map, K key, V defaultValue)
K - 泛型 keyV - 泛型 valuemap - mapkey - keydefaultValue - 默认值public static Map.Entry<String,Object> getFirstEntry(Map<String,Object> map)
map - mappublic static <T> void putToListMap(Map<String,List<T>> listMap, String key, T elem)
T - 泛型listMap - 列表key - 键elem - 元素Copyright © 2024. All rights reserved.