java中String的常用方法

╰半夏微凉° 2023-10-04 16:33 105阅读 0赞

Java语言定义了许多方法。可以通过下列格式调用Java语言定义的方法
字符串变量名.方法名()

  1. 返回字符串的长度

    public int length()

  2. 将给定字符串与当前字符串相比较,若两个字符串相等,则返回true,否则返回false

    public boolean equals(Object anObject)

  3. 返回字符串钟从beginIndex开始到字符串末尾的子串

    public String substring(int beginIndex)

  4. 返回从beginIndex开始到endIndex-1的子串

    1. public String substring(int beginIndex,int endIndex)
  5. 返回index指定位置的字符串

    1. public char charAt(int index)
  6. 返回str在字符串中第一次出现的位置

    1. public int indexOf(String str)
  7. 调用该方法的字符串大于参数字符串大于参数字符串,则返回大于0的值;若相等则返回数0;若小于参数字符串,则返回小于0的值

    1. public int compareTo(String anotherString)
  8. 以newChar字符替换字符串中所有oldChar字符

    1. public String replace(char oldChar,char newChar)
  9. 去掉字符串的首尾字段

    1. public String trim()
  10. 将字符串中所有字符都转换为小写字符

    1. public String toLowerCase()
  11. 将字符串中所有字符都转换为大小写字符

    1. public String toUpperCase()

发表评论

表情:
评论列表 (有 0 条评论,105人围观)

还没有评论,来说两句吧...

相关阅读