java笔记-字符串的处理
String str = "Hello, world!";
// 使用 charAt() 方法获取字符串中指定位置的字符
char firstChar = str.charAt(0);
char fifthChar = str.charAt(5);
int index1 = str.indexOf('o'); // 返回值为 4
int index2 = str.indexOf("world"); // 返回值为 7
indexOf(String str, int fromIndex):从指定的索引位置开始,查找指定字符串在字符串中第一次出现的位置。
String sub2 = str.substring(7, 12); // 返回值为 "world"
如果 beginIndex 等于 endIndex,则返回的子字符串为空字符串。
// 使用 charAt() 方法获取字符串中指定位置的字符
char firstChar = str.charAt(0);
char fifthChar = str.charAt(5);
int index1 = str.indexOf('o'); // 返回值为 4
int index2 = str.indexOf("world"); // 返回值为 7
indexOf(String str, int fromIndex):从指定的索引位置开始,查找指定字符串在字符串中第一次出现的位置。
String sub2 = str.substring(7, 12); // 返回值为 "world"
如果 beginIndex 等于 endIndex,则返回的子字符串为空字符串。
全部评论
相关推荐
点赞 评论 收藏
分享
点赞 评论 收藏
分享
10-30 14:15
东南大学 通信设备工程师
云雨b:没啥用,那个北方光电,10几分钟,还没说完就让下了,一周后就来offer,想要你的,没有时常限制,不想要你的,聊再久也没用 点赞 评论 收藏
分享