ustcyc
2025-04-11 16d77a440e12c3de262c48c79af5fc0494dd87b7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package com.zhitan.common.utils;
 
import com.alibaba.fastjson.JSONObject;
import com.zhitan.common.constant.CommonConst;
 
/**
 * @Description: 字符串工具类
 * @author ZhiTan
 * @date: 2022年02月02日 12:27
 */
public class StringUtil {
    /**
     * 判断字符串是否为空字符串或者Null
     *
     * @param str 需要判断的字符串
     * @return
     */
    public static boolean isEmptyOrNull(String str) {
        if (str == null || CommonConst.EMPTY.equals(str)) {
            return true;
        }
        return false;
    }
 
    /**
     * 字符串如果为空字符串或者Null返回空字符串,否则返回字符串本身的值
     *
     * @param str
     * @return
     */
    public static String ifEmptyOrNullReturnValue(String str) {
        if (isEmptyOrNull(str)) {
            return CommonConst.EMPTY;
        }
        return str;
    }
 
    /**
     * 对象转成json字符串
     *
     * @param obj
     * @return
     */
    public static String toJson(Object obj) {
        return JSONObject.toJSONString(obj);
    }
 
    /**
     * 对象转成JSONObject
     *
     * @param obj
     * @return
     */
    public static JSONObject toJsonObject(Object obj) {
        return JSONObject.parseObject(toJson(obj));
    }
 
    /**
     * 首字母大写
     *
     * @param str
     * @return
     */
    public static String captureWord(String str) {
        str = str.toLowerCase();
        char[] cs = str.toCharArray();
        cs[0] -= 32;
        return String.valueOf(cs);
    }
}