您的位置:首页 > 产品设计 > UI/UE

CharSequence接口在方法定义中的应用

2017-11-13 00:20 211 查看
String 是java中的字符串,它继承于CharSequence。

 StringBuilder 和 StringBuffer都是可变的字符序列。它们都继承于AbstractStringBuilder,实现了CharSequence接口。

但是,StringBuilder是非线程安全的,而StringBuffer是线程安全的。

 


附录:spring StringUtils部分源码
/**
 * Check that the given CharSequence is neither {@code null} nor of length 0.
 * Note: Will return {@code true} for a CharSequence that purely consists of whitespace.
 * <p><pre class="code">
 * StringUtils.hasLength(null) = false
 * StringUtils.hasLength("") = false
 * StringUtils.hasLength(" ") = true
 * StringUtils.hasLength("Hello") = true
 * </pre>
 * @param str the CharSequence to check (may be {@code null})
 * @return {@code true} if the CharSequence is not null and has length
 * @see #hasText(String)
 */
public static boolean hasLength(CharSequence str) {
return (str != null && str.length() > 0);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐