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);
}
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);
}
相关文章推荐
- 泛型的其他应用-接口,方法定义使用,泛型数组,泛型的嵌套设置。
- ETL应用:一种一次获取一个平台接口文件的方法
- JavaDay08--Homework(定义接口和类并调用属性和方法+对象的多态性+打印对象+判定对象相等)
- Android应用(测试/正式)服务器端接口切换方法
- 编写Animal接口,接口声明run()方法定义Bird类和Fish类实现Animal接口编写Bird类和Fish类的测试程序,并调用其中的run()方
- Selenium Webdriver自动化测试设计(webdriver自动化架构设计、定义接口、日志处理、Java Robot类应用)
- Android应用中定义权限的基本方法
- java语言基础(69)——集合框架(泛型的多种应用场景、泛型类、泛型方法、泛型接口)
- 常见设计模式的定义,应用场景和方法
- 二进制流接口应用实例 pack、unpack、ord 函数使用方法
- 提供一个在测试环境中,监控应用服务器的外部接口调用的方法(高峰)
- 封装dpdk接口成静(动)态库(同源同宿、多通道队列收包),然后在C++应用中使用方法
- 1)编写Animal接口,接口中声明run()方法; 2)定义Bird类和Fish类实现Animal接口; 3)编写Bird类和Fish类的测试程序,并调用其中的run()方法
- php pack、unpack、ord 函数使用方法(二进制流接口应用实例)
- 定义一个接口 MediaPlayer,表示家庭影院的一个设备。MediaPlayer 中 包含 play(),stop(), open()三个方法,分别表示播放、停止和开仓功能。
- Hadoop自定义实现Writable/WritableComparable接口的类方法及应用
- 牛客网Java刷题知识点之泛型概念的提出、什么是泛型、泛型在集合中的应用、泛型类、泛型方法、泛型接口、泛型限定上限、泛型限定下限、 什么时候使用上限?泛型限定通配符的体现
- 1)编写Animal接口,接口中声明run()方法; 2)定义Bird类和Fish类实现Animal接口; 3)编写Bird类和Fish类的测试程序,并调用其中的run()方法
- 编写Animal接口,接口中声明run()方法; 2)定义Bird类和Fish类实现Animal接口; )编写Bird类和Fish类的测试程序,并调用其中的run()方法
- ETL应用:一种处理接口的Pro*C实现方法