All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.majingjing.http.client.util.StringUtils Maven / Gradle / Ivy

The newest version!
package cn.majingjing.http.client.util;

import java.nio.charset.StandardCharsets;
import java.util.UUID;

/**
 * 字符串工具类
 *
 * @author MaMarion
 * @date 2020/4/24
 */
public class StringUtils {

    private StringUtils(){}

    /**
     * 判断字符串为空
     * @param s 需要验证的字符串
     * @return boolean 为null 或者 "" 或者 "  "则返回true,否则返回false
     */
    public static boolean isEmpty(String s) {
        return null == s || "".equals(s.trim());
    }

    /**
     * 判断字符串不为空
     * 
     * 
     * @param s 需要验证的字符串
     * @return boolean
     * @see StringUtils#isEmpty(String)
     */
    public static boolean isNotEmpty(String s) {
        return !isEmpty(s);
    }

    public static String bytesToString(byte[] bytes){
        return new String(bytes, StandardCharsets.UTF_8);
    }

    public static byte[] toBytes(String str){
        return str.getBytes(StandardCharsets.UTF_8);
    }

    /**
     * 记录log日志
     *
     * @param s 格式
     * @param obj 参数
     */
    public static String toStrings(String s, Object... obj) {
        StringBuilder sb = new StringBuilder(s);
        for (int i = 0, m = sb.indexOf(BRACKET_PLACEHOLDER); i < obj.length && m > -1; i++, m = sb.indexOf(BRACKET_PLACEHOLDER)) {
            sb.delete(m, m + 2).insert(m, obj[i]);
        }
        return sb.toString();
    }

    public static String guid(){
        return UUID.randomUUID().toString();
    }

    private static final String BRACKET_PLACEHOLDER = "{}";

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy