java8 判断字符串最前面是否有 如果有去除字符串最前面的号
可以使用startsWith()方法来判断字符串最前面是否有,然后使用substring()方法去除最前面的,号。代码如下:
String str = ",hello world";
if(str.startsWith(",")) {
str = str.substring(1);
}
System.out.println(str);
输出结果为:
hello world
这样就去除了字符串最前面的,号。
原文地址: https://www.cveoy.top/t/topic/cyuI 著作权归作者所有。请勿转载和采集!