Java:org.apache.commons.collections4.MapUtils获取Map数据

简介: Java:org.apache.commons.collections4.MapUtils获取Map数据

依赖

<dependency>
  <groupId>org.apache.commons</groupId>
    <artifactId>commons-collections4</artifactId>
    <version>4.4</version>
</dependency>

示例

package com.demo.map;
import org.apache.commons.collections4.MapUtils;
import java.util.HashMap;
import java.util.Map;
public class MapUtilDemo {
    public static void main(String[] args) {
        Map<String, Object> map = new HashMap<>();
        map.put("age", 12);
    // Integer age = (Integer) map.getOrDefault("age", 20);
        Integer age = MapUtils.getInteger(map, "age", 20);
        System.out.println("age: " + age);
        // age: 20
    }
}

如果是字符串类型

Map<String, Object> map = new HashMap<>();
map.put("age", "12");
// Integer age = (Integer) map.getOrDefault("age", 20);
// java.lang.String cannot be cast to java.lang.Integer
Integer age = MapUtils.getInteger(map, "age", 20);
System.out.println("age: " + age);
// age: 12
相关文章
|
Apache
java.lang.NoClassDefFoundError: org/apache/commons/io/output/UnsynchronizedByteArrayOutputStream
java.lang.NoClassDefFoundError: org/apache/commons/io/output/UnsynchronizedByteArrayOutputStream
696 0
org.apache.poi.POIXMLException: java.lang.reflect.InvocationTargetException
org.apache.poi.POIXMLException: java.lang.reflect.InvocationTargetException
104 0
|
缓存 Java 编译器
【Java异常】Error:(19, 21) java: 无法访问org.apache.poi.xwpf.usermodel.ParagraphAlignment 找不到org.apache.po
【Java异常】Error:(19, 21) java: 无法访问org.apache.poi.xwpf.usermodel.ParagraphAlignment 找不到org.apache.po
400 0
|
Dubbo 应用服务中间件
2.7.11,java.lang.NoSuchMethodError: org.apache.curator.framework.recipes.cache.NodeCache.getListenab
2.7.11,java.lang.NoSuchMethodError: org.apache.curator.framework.recipes.cache.NodeCache.getListenab
|
Java 应用服务中间件 Maven
org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1188) - Java
org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1188) - Java
java.lang.ClassNotFoundException: org.apache.commons.fileupload.disk.DiskFileItemFactory
您好,我是码农飞哥,感谢您阅读本文!本文主要介绍文件上传报的错
174 0
|
Apache
找不org.apache.commons.lang3.builder.EqualsBuilder和commons-lang下载链接
找不org.apache.commons.lang3.builder.EqualsBuilder和commons-lang下载链接
132 0
|
Windows
java.lang.UnsatisfiedLinkError:org.apache.hadoop.util.NativeCrc32.nativeComputeChunkedSumsByteArray
java.lang.UnsatisfiedLinkError:org.apache.hadoop.util.NativeCrc32.nativeComputeChunkedSumsByteArray
201 0
java.lang.UnsatisfiedLinkError:org.apache.hadoop.util.NativeCrc32.nativeComputeChunkedSumsByteArray
|
Java Apache
org.apache.tomcat.util.bcel.classfile.ClassFormatException: It is not a Java .class file
Tomcat启动时输出以下错误: 24-May-2015 14:47:07.441 SEVERE [localhost-startStop-1] org.apache.catalina.
1652 0
Java:org.apache.commons.collections4.MapUtils获取Map数据
Java:org.apache.commons.collections4.MapUtils获取Map数据
255 0

热门文章

最新文章

推荐镜像

更多