java.lang.String.trim(), 不仅仅去掉空格
public String trim() {
int len = value.length;
int st = 0;
char[] val = value; /* avoid getfield opcode */ while ((st < len) && (val[st] <= ' ')) {
st++;
}
while ((st < len) && (val[len - 1] <= ' ')) {
len--;
}
return ((st > 0) || (len < value.length)) ? substring(st, len) : this;
}
Returns a string whose value is this string, with any leading and trailing whitespace removed.
If this String object represents an empty character sequence, or the first and last characters of character sequence represented by this String object both have codes greater than '\u005Cu0020' (the space character), then a reference to this String object is returned.
Otherwise, if there is no character with a code greater than '\u005Cu0020' in the string, then a String object representing an empty string is returned.
Otherwise, let k be the index of the first character in the string whose code is greater than '\u005Cu0020', and let m be the index of the last character in the string whose code is greater than '\u005Cu0020'. A String object is returned, representing the substring of this string that begins with the character at index k and ends with the character at index m-that is, the result of this.substring(k, m + 1).
This method may be used to trim whitespace (as defined above) from the beginning and end of a string.
Returns:
A string whose value is this string, with any leading and trailing white space removed, or this string if it has no leading or trailing white space.
java.lang.String.trim(), 不仅仅去掉空格的更多相关文章
- Java笔记之java.lang.String#trim
String的trim()方法是使用频率频率很高的一个方法,直到不久前我不确定trim去除两端的空白符时对换行符是怎么处理的点进去看了下源码的实现,才发现String#trim的实现跟我想像的完全不一 ...
- 117、Java中String类之去掉左右空格
01.代码如下: package TIANPAN; /** * 此处为文档注释 * * @author 田攀 微信382477247 */ public class TestDemo { public ...
- java.lang.String
1.String 是一个类,广泛应用于 Java 程序中,相当于一系列的字符串.在 Java 语言中 strings are objects.创建一个 strings 最直接的方式是 String g ...
- java:常用类(包装类,equals和==的比较,Date,java.lang.String中常用方法,枚举enum)
*包装类: 将基本类型封装成类,其中包含属性和方法以方便对象操作. *byte---->Byte *short--->Short *long--->Long *float---> ...
- javax.el.PropertyNotFoundException: Property 'name' not found on type java.lang.String
javax.el.PropertyNotFoundException: Property 'name' not found on type java.lang.String javax.el.Bean ...
- groovy --不注意的小错误(java.lang.String.positive() is applicable)
sql 语句拼接报错: No signature of method: java.lang.String.positive() is applicable for argument types: () ...
- java中string.trim()函数的使用
java中string.trim()函数的的作用是去掉字符串开头和结尾的空格,防止不必要的空格导致的错误. public static void main(String arg[]){ String ...
- java.lang.String 类源码解读
String类定义实现了java.io.Serializable, Comparable<String>, CharSequence 三个接口:并且为final修饰. public fin ...
- java.lang.String & java.lang.StringBuilder
java.lang.String & java.lang.StringBuilder String 成员方法 作用 public charAr(int index) 返回给定位置的代码单元 p ...
随机推荐
- Django中构造响应对象的方式
1 HttpResponse 可以使用django.http.HttpResponse来构造响应对象. HttpResponse(content=响应体, content_type=响应体数据类型, ...
- 2018.11.12 RF debug
1 SG setting 2 Date 3 0-1 4 ASK 5 Power supply 6 SG - filter 7 NRF905- demodulation 8 RX test 9 ...
- 报错:java.lang.IllegalArgumentException: object is not an instance of declaring class
反射的报错信息如下: java.lang.IllegalArgumentException: object is not an instance of declaring class at sun.r ...
- Popular HashMap and ConcurrentHashMap Interview Questions
http://howtodoinjava.com/core-java/collections/popular-hashmap-and-concurrenthashmap-interview-quest ...
- SpringMVC札集(10)——SSM框架整合
自定义View系列教程00–推翻自己和过往,重学自定义View 自定义View系列教程01–常用工具介绍 自定义View系列教程02–onMeasure源码详尽分析 自定义View系列教程03–onL ...
- 使用ElasticSearch完成百万级数据查询附近的人功能
上一篇文章介绍了ElasticSearch使用Repository和ElasticSearchTemplate完成构建复杂查询条件,简单介绍了ElasticSearch使用地理位置的功能. 这一篇我们 ...
- 利用pandas随机切分csv文件
把数据集随机切分为训练集和测试集 method 1: df = pd.read_csv('data/tgnb_merge.csv', encoding='utf-8') df.drop_duplica ...
- java之接口
背景 为了防止[多重继承]:(在面向对象的编程语言(例如java)中,指一个类可以同时继承多个父类的行为和特征功能)所引发的"致命方块",出现了接口. 使用 定义 public ...
- MySQL中的锁理解
1.目的:解决客户端并发访问的冲突问题 2.锁的分类 1.锁类型 1.读锁(共享锁) 查询(select):加读锁之后,别人不能更改表记录,但是可以进行查询. 2.写锁(互斥锁,排他锁) 更新(upd ...
- 阿里面试题,N个士兵的通话问题
战场上不同的位置有N个战士(n>4),每个战士知道当前的一些战况,现在需要这n个战士通过通话交流,互相传达自己知道的战况信息,每次通话,可以让通话的双方知道对方的所有情报,设计算法,使用最少的通 ...