您的位置:首页 > 编程语言 > Java开发

java的String类

2016-07-08 16:02 681 查看
1.字符串的创建

(1)public String()
创建一个空的字符串
(2)public String( String s )
 用已有的字符创建新的String
(3)public String ( StringBuffer buf )
用StringBuffer对象创建
(4)public String ( char value[ ] )
用字符数组创建

 
2.字符串的连接

利用“+”运算符进行连接

 
3.字符串的比较

(1)boolean equals ( object Obj )
(2)boolean equalsIgnoreCase ( String Str ) 忽略大小写,判断两串是否相等
(3)int compareTo ( String Str ) 当前串大,返回>0;当前串小,返回<0;相等返回0
 

4.字符串的提取和替换

(1)char charAt ( int index ) 返回指定位置的字符
(2)String substring ( int begin ) 返回从begin位置开始的子字符串
(3)String substring ( int begin, int end ) 返回从begin位置开始到end-1位置的字符串,长度为end - begin
(4)String replace ( char ch1, char ch2 ) 将字符串中的ch1 换成 ch2
(5)String replaceAll ( String regex, String replacement ) 将字符串中的regex换成replacement
(6)String trim () 将当前字符串的前部空格和尾部空格去掉
(7)String toUpperCase () 全部变成大写字母
(8)String toLowerCase () 全部变成小写字母
 

5.字符串的查找

(1)int indexOf ( int ch )

ch首次出现的位置
(2)int indexOf ( int ch, int start )

ch首次出现的位置>=start
(3)int intdexOf ( String str )
 str首次出现的位置
(4)int indexOf ( String str, int start )

str首次出现的位置>=start
(5)int lastIndexOf ( int ch ) 

ch最后出现的位置
(6)int lastIndexOf ( int ch, int start )
 ch最后出现的位置<=start
(7)int lastIndexOf ( String str )
 str最后出现的位置
(8)int lastIndexOf ( String str, int start )
 str最后出现的位置<=start
(9)boolean startaWith ( String prefix )
判断字符串是否为当前字符串前缀
(10)boolean endsWith (String postfix )
判断字符串是否为当前字符串后缀
 

 
 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: