StringUtils - 字符串处理
判空
StringUtils.isEmpty(str); // null 或 ""
StringUtils.isNotEmpty(str);
StringUtils.isBlank(str); // null 或 空白字符
StringUtils.isNotBlank(str);
StringUtils.isAnyEmpty(str1, str2);
StringUtils.isAnyBlank(str1, str2); // 任意空白
StringUtils.isAllBlank(str1, str2); // 全部空白
格式化
StringUtils.formatMsg("Hello {}, welcome to {}", name, site); // {} 占位符
StringUtils.formatMsg("Value {0} is {1}", "name", "John"); // 索引占位符
// JSONMap 模板替换
JSONMap params = new JSONMap("name", "John", "age", "30");
StringUtils.formatMsg("Hello ${name}, you are ${age} years old", params);
// → "Hello John, you are 30 years old"
拼接
StringUtils.join(",", "a", "b", "c"); // "a,b,c"
StringUtils.join(array, ","); // 数组连接
StringUtils.join(list, ","); // 集合连接
StringUtils.join(list, ','); // 字符分隔符
判断
StringUtils.isNumber("123.45"); // true(数值格式校验)
StringUtils.isLongOrInt("123"); // true
StringUtils.startsWith("hello", "hel"); // true
StringUtils.startsWithAny("hello", "he", "ha"); // 判断以任一开头
转换
StringUtils.capitalize("hello"); // "Hello"
StringUtils.addZeroBefor(42, 5); // "00042"
StringUtils.leftPad("text", 10, '0'); // "000000text"
StringUtils.repeat('*', 5); // "*****"
StringUtils.NVL(null); // ""
StringUtils.NVL(null, "默认值"); // "默认值"
Bean ID 生成
StringUtils.getBeanId("com.example.UserService"); // "userService"
StringUtils.getBeanId(UserService.class); // "userService"
数组/列表转换
List<String> list = StringUtils.arrayToList(array);
String[] array = StringUtils.listToArray(list);
分割
String[] parts = StringUtils.split("a,b,c", ","); // 按正则分割