String中常用的方法

String中常用的方法

1. public char charAt(int index)

   返回字符串中的index个字符
2. public int length()
   返回字符串长度
3. public int indexOf(String str)
   返回字符串中出现str的第一个位置

  public int  lastIndexOf(String str)

返回字符串中出现str的最后一个位置。

4. public Boolean equals(String s):

比较字符串与another是否相同

public boolean equalsIgnoreCase(String another)
   比较字符串与another是否相同(忽略大小写)

equals()方法比较字符串对象中的字符,==运算符比较两个对象是否引用同一实例
5. public String replace(char oldChar, char newChar)
   在字符串中用newChar替换oldChar

String replace(CharSequence original,CharSequence replacement)

用一个字符序列replacement替换另一个字符序列original

6. public boolean startsWith(String prefix)
   判断字符串是否以prefix开头
7. public boolean endsWith(String suffix)
   判断字符串是否以suffix结束
8. public String toUpperCase()
   返回该字符串的大写形式
9. public String toLowerCase()
   返回该字符串的小写形式
10. public String substring(int beginIndex)
   返回该字符串从beginIndex开始到结尾的子串
11. public String substring(int beginIndex,int endIndex)
   返回该字符串从beginIndex开始到endIndex结尾的子串
13. public String trim()

   去除字符串头尾的空格

14. public int compareTo(String s):

如果当前字符串与s相同,返回值得0;如果大于s,返回正值;如果小于s,则返回负值

   public int compareToIgnore(String s):忽略大小写的比较

15.public Boolean regionMatches (int firstStart,String other,int otherStart,int length):

用于比较一个字符串中特定区域与另一特定区域

public Boolean regionMatches (Boolean b, int firstStart, String other, int otherStart, int  length)

可以通过参数b决定是否忽略大小写。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值