首页 > 代码库 > 从源码分析StringUtils包

从源码分析StringUtils包

今天用到StringUtils.join方法,闲来无聊,看了下源码

 

当然不可能自己分析,你傻啊,在这里推荐一个别人分析的;

http://blog.csdn.net/baidu_31071595/article/details/51320622

 

首先导包

import org.apache.commons.lang3.StringUtils;

我在这里调用的是StringUtils.join方法

public static String join(Object[] array, char separator)

把数组中的元素连接成一个字符串返回,把分隔符separator也加上。

举例(*表示任意):

StringUtils.join(null, *)                        = null

StringUtils.join({}, *)                          = ""

StringUtils.join({null}, *)                      = ""

StringUtils.join({"as","df","gh","jk"}, ))     = "as df gh jk"

StringUtils.join({"as","df","gh","jk"},.))     = "as.df.gh.jk"

StringUtils.join({"as","","df","gh"},.))       = "as..df.gh"

StringUtils.join({"","as","","","df","",""},,))= ",as,,,df,,"

StringUtils.join({"","as","","","df","",""}, ))= " as   df "

StringUtils.join({"as.df.gh"},.))                 = "as.df.gh"

StringUtils.join({"as.df.gh"}, ))              = "as.df.gh"

 

 

 

 

over...

从源码分析StringUtils包