java的String类

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 )

判断字符串是否为当前字符串后缀

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值