StringUtils.defaultIfEmpty()方法

来源:互联网 发布:三菱plc编程代码 编辑:程序博客网 时间:2024/06/06 11:08


public static String defaultIfEmpty(String str,
                                    String defaultStr)

如果str为空,则返回defaultStr。否则返回str;

附官方解释:

defaultIfEmpty

public static String defaultIfEmpty(String str,                                      String defaultStr)
Returns either the passed in String, or if the String is empty or null, the value of defaultStr.
 StringUtils.defaultIfEmpty(null, "NULL")  = "NULL"   StringUtils.defaultIfEmpty("", "NULL")    = "NULL"   StringUtils.defaultIfEmpty("bat", "NULL") = "bat"   StringUtils.defaultIfEmpty("", null)      = null   

Parameters:

str- the String to check, may be null

defaultStr- the default String to return if the input is empty ("") or null, may be null
Returns:
the passed in String, or the default
0 0
原创粉丝点击