JAVA 获取字符串的长度,链接字符串,获取字符串索引位置的值,获取值的索引位置

package Code503;

public class CodeStringGet {
public static void main(String[] args) {
//获取字符串的长度
int length = "huanduchenyu".length();
System.out.println("字符串的长度为:"+length);
String str1="欢都";
String str2="辰玉";
//链接字符串
String str3=str1.concat(str2);
System.out.println(str1);
System.out.println(str2);
System.out.println(str3);
//获取字符串,索引为2的值
System.out.println(str3.charAt(2));
//获取“玉”字在字符串的索引位置
int index = str3.indexOf("玉");
System.out.println("玉出现的位置是:"+index);
}
}
运行代码↓


猜你喜欢

转载自www.cnblogs.com/Ssinoo/p/10806944.html