频道直达 - 专题 - 新闻 - 技巧 - 组网 - 开发 - 安全 - web编程 - 图像 - 操作系统 - 数据库 - 教育 - 旅游 - 健康 - 时尚 - 驱动 - 软件 - 游戏 - 多媒体 - ERP - 讨论组

StringUtils工具类的使用

来源:中国IT实验室 作者:佚名 出处:巧巧读书 2008-05-29 进入讨论组
下一页 1 2 3 

    一、数组转成字符串:
    1、 将数组中的字符转换为一个字符串
    将数组中的字符转换为一个字符串

    @param strToConv 要转换的字符串 ,默认以逗号分隔
    @return 返回一个字符串
    String[3] s={"a","b","c"}
    StringUtil.convString(s)="a,b,c"
    2、 static public String converString(String strToConv)
    @param strToConv 要转换的字符串 ,
    @param conv 分隔符,默认以逗号分隔
    @return 同样返回一个字符串

    String[3] s={"a","b","c"}
    StringUtil.convString(s,"@")="a@b@c"
    static public String converString(String strToConv, String conv)


    二、空值检测:
    3、

    Checks if a String is empty ("") or null.


    判断一个字符串是否为空,空格作非空处理。 StringUtils.isEmpty(null) = true StringUtils.isEmpty("") = true StringUtils.isEmpty(" ") = false StringUtils.isEmpty("bob") = false StringUtils.isEmpty(" bob ") = false

    NOTE: This method changed in Lang version 2.0.

    It no longer trims the String.
    That functionality is available in isBlank().


    @param str the String to check, may be null
    @return true if the String is empty or null
    public static boolean isEmpty(String str)


    三、非空处理:
    4、
    Checks if a String is not empty ("") and not null.


    判断一个字符串是否非空,空格作非空处理. StringUtils.isNotEmpty(null) = false StringUtils.isNotEmpty("") = false StringUtils.isNotEmpty(" ") = true StringUtils.isNotEmpty("bob") = true StringUtils.isNotEmpty(" bob ") = true

    @param str the String to check, may be null
    @return true if the String is not empty and not null
    public static boolean isNotEmpty(String str)

    5、

    Checks if a String is not empty (""), not null and not whitespace only.


    判断一个字符串是否非空,空格作空处理. StringUtils.isNotBlank(null) = false StringUtils.isNotBlank("") = false StringUtils.isNotBlank(" ") = false StringUtils.isNotBlank("bob") = true StringUtils.isNotBlank(" bob ") = true

    @param str the String to check, may be null
    @return true if the String is
    not empty and not null and not whitespace
    @since 2.0
    public static boolean isNotBlank(String str)


    四、 空格处理
    6、
    Removes control characters (char <= 32) from both

    ends of this String, handling null by returning
    null.


    The String is trimmed using {@link String#trim()}.

    Trim removes start and end characters <= 32.
    To strip whitespace use {@link //strip(String)}.


    To trim your choice of characters, use the

    {@link //strip(String, String)} methods.


    格式化一个字符串中的空格,有非空判断处理; StringUtils.trim(null) = null StringUtils.trim("") = "" StringUtils.trim(" ") = "" StringUtils.trim("abc") = "abc" StringUtils.trim(" abc ") = "abc"

    @param str the String to be trimmed, may be null
    @return the trimmed string, null if null String input
    public static String trim(String str)

    7、


    Removes control characters (char <= 32) from both

    ends of this String returning null if the String is
    empty ("") after the trim or if it is null.

    The String is trimmed using {@link String#trim()}.

    Trim removes start and end characters <= 32.
    To strip whitespace use {@link /stripToNull(String)}.


    格式化一个字符串中的空格,有非空判断处理,如果为空返回null; StringUtils.trimToNull(null) = null StringUtils.trimToNull("") = null StringUtils.trimToNull(" ") = null StringUtils.trimToNull("abc") = "abc" StringUtils.trimToNull(" abc ") = "abc"

    @param str the String to be trimmed, may be null
    @return the trimmed String,
    null if only chars <= 32, empty or null String input
    @since 2.0
    public static String trimToNull(String str)

    8、


    Removes control characters (char <= 32) from both

    ends of this String returning an empty String ("") if the String
    is empty ("") after the trim or if it is null.

    The String is trimmed using {@link String#trim()}.

    Trim removes start and end characters <= 32.
    To strip whitespace use {@link /stripToEmpty(String)}.


    格式化一个字符串中的空格,有非空判断处理,如果为空返回""; StringUtils.trimToEmpty(null) = "" StringUtils.trimToEmpty("") = "" StringUtils.trimToEmpty(" ") = "" StringUtils.trimToEmpty("abc") = "abc" StringUtils.trimToEmpty(" abc ") = "abc"

    @param str the String to be trimmed, may be null
    @return the trimmed String, or an empty String if null input
    @since 2.0
    public static String trimToEmpty(String str)

进入讨论组讨论。
下一页 1 2 3 
收藏此文】【 】【打印】【关闭
相关图文阅读
频道图文推荐
健 康 咨 询
时 尚 咨 询
巧巧读书宗旨
相关专题
讨论组问题推荐
站内各频道最新更新文档
站内最新制作专题
热门关键字导读
Photoshop教 程照片处理 照片制作 PS快捷键 抠图
计 算 机 故 障XP系统修复
艺 术 与 设 计设计 流媒体 设计欣赏 边框
计 算 机 安 全ARP
站内频道文章精选
巧巧电脑频道编辑信箱  告诉我们您想看的专题或文章