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 ...
随机推荐
- java中的一些执行顺序,代码块,静态,构造,成员。。。。(转的)
Java初始化顺序(转来的) 1在new B一个实例时首先要进行类的装载.(类只有在使用New调用创建的时候才会被java类装载器装入) 2,在装载类时,先装载父类A,再装载子类B3,装载父类A后,完 ...
- ES的Zen发现机制
ES的Zen发现机制 Zen发现机制是ElasticSearch默认的发现模块.它提供的是单播发现,但是可被拓展为支持云环境下或者其他形式的发现机制.zen 发现模块集成了其他模块,如在发现期间,节点 ...
- final方法,abstract方法和abstract类,native方法
final方法 1.为了确保某个函数的行为在继承过程中保持不变,并且不能被覆盖(override),可以使用final方法. 2.为了效率上的考虑,将方法声明为final,让编译器对此方法的调用进行优 ...
- 使用stringstream类
当需要格式化int类型为字符串时,可以使用这个类, 需要包含这个文件头: #include <sstream> 然后这样使用: //打开保存进度的RPG文件. std::stringstr ...
- angular2.0学习日记1
使用NG2之前需要安装node以及Npm环境,并到node下下载ng2所需要得文件,具体配置请到https://angular.cn/docs/ts/latest/quickstart.html按照提 ...
- HDU 1033
http://acm.hdu.edu.cn/showproblem.php?pid=1033 这题的题干说的很绕,结合样例不难理解题意,走折线,A代表顺时针,V代表逆时针,给一个包含A和V的字符串,输 ...
- Objective C----手动管理内存和自动管理内存
对象的引用计数(Reference Counting) 正常情况下,当一段代码需要访问某个对象时,该对象的引用的计数加1:当这段代码不再访问该对象时,该对象的引用计数减1,表示这段代码不再访问该对象: ...
- c++学习笔记(5)
1.两个相邻的仅由空格,制表符或者换行符分开的字符串字面值,可连接成一个新的字符串 cout<<"a multi-line " "string literal ...
- BZOJ4975: [Lydsy1708月赛]区间翻转( 博弈&逆序对)
4975: [Lydsy1708月赛]区间翻转 Time Limit: 1 Sec Memory Limit: 256 MBSubmit: 265 Solved: 140[Submit][Stat ...
- JSP、Java和Servlet获取当前工程的路径
JSP.Java和Servlet获取当前工程的路径: 1.JSP中取得路径: 以工程名为TEST为例: (1)得到包含工程名的当前页面全路径:request.getRequestURI()结果:/TE ...