String类常用的方法
2017-09-28 19:08
246 查看
char charAt(int index)
返回给定位置的代码单元。除非对底层的代码单元感兴趣,否则不需要调用这个方法。
int codePointAt(int index)
返回从给定位置开始或结束的代码点。
int offsetByCodePoints(int startIndex, int cpCount)
返回从startIndex代码点开始,位移cpCount后的代码索引。
int compareTo(String other)
按照字典顺序,如果字符串位于other之前,返回一个负数;如果字符串位于other之后,返回一个正数;如果两个字符串相等,返回0。
boolean endWith(String suffix)
如果字符串以suffix结尾,返回true。
boolean equals(Object other)
如果字符串与other相等,返回true;
boolean equalsIgnoreCase(String other)
如果字符串与other(忽略大小写),返回true。
int indexOf(String str)
int indexOf(String str, int fromIndex)
int indexOf(int cp)
int indexOf(int cp, int fromIndex)
返回与字符串str或代码点cp匹配的第一个子串的开始位置。这个位置从索引0或fromIndex开始计算。如果在原始串中不存在str,返回-1。
int lastIndexOf(String str)
int lastIndexOf(String str, int formIndex)
int lastIndexOf(int cp)
int lastIndexOf(int cp, int fromIndex)
返回与字符串str或代码点cp匹配的最后一个子串的开始位置
int length()
返回字符串的长度。
int codePointCount(int startIndex, int endIndex)
返回startIndex和endIndex-1之间的代码点数量。没有配成对的代用字符将计入代码点。
String replace(CharSequence oldString, charSequence newString)
返回一个新字符串,这个字符串用newString代替原始字符串中所有的oldString。可以用String或StringBuilder对象作为CharSequence参数。
boolean startsWith(String prefix)
如果字符串以prefix字符串开始,返回true。
String substring(int beginIndex)
String substring(int beginIndex, int endIndex)
返回一个新字符串。这个字符串包含原始字符串中从beginIndex到串尾或endIndex-1的所有代码单元。
String toLowerCase()
返回一个新字符串。这个字符串将原始字符串中的所有大写字母改成了小写字母。
String toUpperCase()
返回一个新字符串。这个字符串将原始字符串中的所有小写字母改成了大写字母。
String trim()
返回一个新字符串,这个字符串将删除了原始字符串头部和尾部的空格
返回给定位置的代码单元。除非对底层的代码单元感兴趣,否则不需要调用这个方法。
int codePointAt(int index)
返回从给定位置开始或结束的代码点。
int offsetByCodePoints(int startIndex, int cpCount)
返回从startIndex代码点开始,位移cpCount后的代码索引。
int compareTo(String other)
按照字典顺序,如果字符串位于other之前,返回一个负数;如果字符串位于other之后,返回一个正数;如果两个字符串相等,返回0。
boolean endWith(String suffix)
如果字符串以suffix结尾,返回true。
boolean equals(Object other)
如果字符串与other相等,返回true;
boolean equalsIgnoreCase(String other)
如果字符串与other(忽略大小写),返回true。
int indexOf(String str)
int indexOf(String str, int fromIndex)
int indexOf(int cp)
int indexOf(int cp, int fromIndex)
返回与字符串str或代码点cp匹配的第一个子串的开始位置。这个位置从索引0或fromIndex开始计算。如果在原始串中不存在str,返回-1。
int lastIndexOf(String str)
int lastIndexOf(String str, int formIndex)
int lastIndexOf(int cp)
int lastIndexOf(int cp, int fromIndex)
返回与字符串str或代码点cp匹配的最后一个子串的开始位置
int length()
返回字符串的长度。
int codePointCount(int startIndex, int endIndex)
返回startIndex和endIndex-1之间的代码点数量。没有配成对的代用字符将计入代码点。
String replace(CharSequence oldString, charSequence newString)
返回一个新字符串,这个字符串用newString代替原始字符串中所有的oldString。可以用String或StringBuilder对象作为CharSequence参数。
boolean startsWith(String prefix)
如果字符串以prefix字符串开始,返回true。
String substring(int beginIndex)
String substring(int beginIndex, int endIndex)
返回一个新字符串。这个字符串包含原始字符串中从beginIndex到串尾或endIndex-1的所有代码单元。
String toLowerCase()
返回一个新字符串。这个字符串将原始字符串中的所有大写字母改成了小写字母。
String toUpperCase()
返回一个新字符串。这个字符串将原始字符串中的所有小写字母改成了大写字母。
String trim()
返回一个新字符串,这个字符串将删除了原始字符串头部和尾部的空格
相关文章推荐
- java面向对象中的String类中12种常用的方法
- Java基础:String类之常用方法及使用注意事项
- String类的常用方法
- Java基础-String类的常用方法与对应源码
- java中String类常用方法的使用与实例
- String类的常用方法
- java中String类常用方法总结
- String类常用方法1
- C#中String类常用方法汇总
- 黑马程序员_11_String类的常用方法
- 一个程序学习String类的所有常用方法
- Java-String类的常用方法总结
- Java-String类的常用方法总结
- String类的一些常用方法
- String类中常用方法汇总整理(常用API)
- java中String类的常用方法
- Java中字符串String类常用方法示例
- Java String类的常用方法(字符与字符串)
- String类常用方法之charAt()、codePointAt()示例
- 常用的String类方法