java8 查找字符串里面第一次出现的冒号内容
你可以使用indexOf方法来查找字符串中第一次出现的冒号,并使用substring方法来截取冒号后面的内容。以下是一个示例代码:
public class Main {
public static void main(String[] args) {
String str = "Java8: Find the first occurrence of colon in a string";
int index = str.indexOf(":"); // 查找冒号的位置
if (index != -1) {
String content = str.substring(index + 1); // 截取冒号后面的内容
System.out.println("冒号后面的内容是: " + content);
} else {
System.out.println("字符串中没有冒号");
}
}
}
输出结果为:
冒号后面的内容是: Find the first occurrence of colon in a string
``
原文地址: https://www.cveoy.top/t/topic/hWdC 著作权归作者所有。请勿转载和采集!