1. 比较连个字符串的大小
??字符串的 compareTo 方法,比较连个字符串的大小
public static void main(String[] args) {
String s1 = "第一章";
String s2 = "第二章";
System.out.println(s1.compareTo(s2));
}
2. 判断集合内容是否为空
package com.peng.producer;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.List;
public class Demo {
public static void main(String[] args) {
List<Integer> list = new ArrayList<>();
list.add(1);
if (!CollectionUtils.isEmpty(list)) {
System.out.println("集合内容不为空");
}
}
}
3. 判断字符串内容是否为空
(1) 引入依赖
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
(2) 示例
package com.peng.producer;
import org.apache.commons.lang.StringUtils;
public class Demo {
public static void main(String[] args) {
String str = "school";
if (StringUtils.isNotEmpty(str)) {
System.out.println("字符串不为空");
}
}
}
|