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  忽视大小写。

原文地址:https://www.cnblogs.com/java-dog/p/5188202.html