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,则返回的子字符串为空字符串。
全部评论
相关推荐
PDD暑期实习内推看...:同学,考虑一下我们这里吗,招实习生啦:https://careers.pddglobalhr.com/campus/intern?t=FFEgIPlwIe
查看17道真题和解析 点赞 评论 收藏
分享
04-01 18:11
南京航空航天大学 golang 点赞 评论 收藏
分享

