温馨提示×

Java的isnull方法有哪些常见用法

小樊
85
2024-08-15 12:54:34
栏目: 编程语言
Java开发者专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

  1. 判断对象是否为null:
Object obj = null;
if (Objects.isNull(obj)) {
    System.out.println("对象为空");
}
  1. 判断字符串是否为null或空字符串:
String str = null;
if (str == null || str.isEmpty()) {
    System.out.println("字符串为空");
}
  1. 判断集合是否为null或空集合:
List<String> list = null;
if (list == null || list.isEmpty()) {
    System.out.println("集合为空");
}
  1. 判断数组是否为null或空数组:
String[] array = null;
if (array == null || array.length == 0) {
    System.out.println("数组为空");
}

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读:C# Split方法有哪些不常见的用法

0