String类中常用的方法

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了String类中常用的方法相关的知识,希望对你有一定的参考价值。

int length(); 返回字符串的长度 

public static void main(String[] args){

  String str = "HelloWorld!";

  int x= str.length();

  System.out.println(str+"长度"+x);

}

char charAt(int index);返回index+1位置的字符 

public static void main(String[] args){

  String str ="HelpWorld!";

  System.out.println(str.charAt(3));

}

输出结果:

p

p正好是inedx+1位,即3+1,第四位的p

-----------------------------

boolean equals(String obj) 和 boolean equalsIgnoreCase(String str)   Ignore[ig‘?r]忽略,无视;驳回(诉讼) IgnoreCase  忽视大小写。

 

以上是关于String类中常用的方法的主要内容,如果未能解决你的问题,请参考以下文章

String类中的常用方法

如何将 View 类中的代码片段移动到 OnAppearing() 方法?

String类中常用方法:

27 string类中常用的方法列表

String类中常用的方法(重要)

String类中intern方法的原理分析