網站首頁 編程語言 正文
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>4.2</version>
</dependency>
包:org.apache.commons.collections4
public static void main(String[] args) {
// 批量賦值
Map<String, Object> colorMap = MapUtils.putAll(new HashMap<>(),
new Object[] { "str", "我是字符串", "boo", true, "num", 1000 });
System.out.println("colorMap:" + colorMap.toString()); // colorMap:{str=我是字符串, boo=true, num=1000}
System.out.println("colorMap-isEmpty:" + MapUtils.isEmpty(colorMap)); // colorMap-isEmpty:false
System.out.println("colorMap-isNotEmpty:" + MapUtils.isNotEmpty(colorMap)); // colorMap-isNotEmpty:true
// 獲取值,還有其他類型可以看MapUtils的API方法
String str = MapUtils.getString(colorMap, "str");
System.out.println("str:" + str); // str:我是字符串
Boolean boo = MapUtils.getBoolean(colorMap, "boo");
System.out.println("boo:" + boo); // boo:true
Integer num = MapUtils.getInteger(colorMap, "num");
System.out.println("num:" + num); // num:1000
String not = MapUtils.getString(colorMap, "not");
System.out.println("not:" + not); // not:null
not = MapUtils.getString(colorMap, "not", "未知");
System.out.println("not:" + not); // not:未知
// 為NULL的情況設置值
colorMap = MapUtils.emptyIfNull(null);
System.out.println("colorMap:" + colorMap.toString()); // colorMap:{}
System.out.println("colorMap-isEmpty:" + MapUtils.isEmpty(colorMap)); // colorMap-isEmpty:true
System.out.println("colorMap-isNotEmpty:" + MapUtils.isNotEmpty(colorMap)); // colorMap-isNotEmpty:false
// 判斷值
colorMap = null;
System.out.println("colorMap-isEmpty:" + MapUtils.isEmpty(colorMap)); // colorMap-isEmpty:true
System.out.println("colorMap-isNotEmpty:" + MapUtils.isNotEmpty(colorMap)); // colorMap-isNotEmpty:false
}
原文鏈接:https://blog.csdn.net/qq_43985303/article/details/135235853
- 上一篇:沒有了
- 下一篇:沒有了
相關推薦
- 2022-01-27 editor.md第一行解析失敗,解析成代碼模塊原始輸出
- 2022-05-03 C#面向對象設計原則之組合/聚合復用原則_C#教程
- 2022-08-15 springboot的熱部署配置
- 2022-05-06 golang-操作sqlite3增刪改查
- 2022-08-30 android屏幕適配sw規則
- 2023-10-13 CSS點擊切換或隱藏盒子的卷起、展開效果
- 2022-05-31 使用python把Excel中的數據在頁面中可視化_python
- 2022-06-06 layui 日期格式不正確(date、datetime)區別
- 欄目分類
-
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支