org.springframework.util.ObjectUtils

org.springframework.util.ObjectUtils



获取对象的基本信息:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
String str = null;
// 获取对象的类名。参数为 null 时,返回字符串:"null"
String s = ObjectUtils.nullSafeClassName(str);
System.out.println(s);// null
// 参数为 null 时,返回 0
int i = ObjectUtils.nullSafeHashCode(str);
System.out.println(i);// 0
// 参数为 null 时,返回字符串:"null"
String s1 = ObjectUtils.nullSafeToString(str);
System.out.println(s1);// null
// 获取对象 HashCode(十六进制形式字符串)。参数为 null 时,返回 0
String identityHexString = ObjectUtils.getIdentityHexString(str);
System.out.println(identityHexString);// 0
// 获取对象的类名和 HashCode。 参数为 null 时,返回字符串:""
String s2 = ObjectUtils.identityToString(str);
System.out.println(s2);
// 相当于 toString()方法,但参数为 null 时,返回字符串:""
String displayString = ObjectUtils.getDisplayString(str);
System.out.println(displayString);

  

判断方法:

1
2
3
4
5
6
7
8
9
10
11
12
// 判断数组是否为空
boolean empty = ObjectUtils.isEmpty(strArr);
System.out.println(empty);// true
// 判断参数对象是否是数组
boolean array = ObjectUtils.isArray(strArr);
System.out.println(array);// true
// 判断数组中是否包含指定元素
boolean aa1 = ObjectUtils.containsElement(strArr2, "aa1");
System.out.println(aa1);// true
// 相等,或同为 null时,返回 true
boolean b = ObjectUtils.nullSafeEquals(null, null);
System.out.println(b);// true

  

 其他方法:

1
2
3
4
5
6
// 向参数数组的末尾追加新元素,并返回一个新数组
Integer[] integers = ObjectUtils.addObjectToArray(intArr2, 4);
System.out.println(ArrayUtils.toString(integers));//{1,2,3,4}
// 原生基础类型数组 --> 包装类数组
Object[] objects = ObjectUtils.toObjectArray(intArr);
System.out.println(ArrayUtils.toString(objects));//{1,2,3}

  

 

posted @   草木物语  阅读(529)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
历史上的今天:
2020-01-30 通过 Socket 实现 UDP 编程
2020-01-30 通过 Socket 实现 TCP 编程
2020-01-30 Java中网络相关API
2019-01-30 response 输出中文数据 文件下载
点击右上角即可分享
微信分享提示