您的位置:首页 > 其它

String类中常用的方法

2016-02-13 19:09 274 查看
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 忽视大小写。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: