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类中常用的方法的主要内容,如果未能解决你的问题,请参考以下文章