您的位置:首页 >java中startsWith方法有什么用
发布于2023-05-01 阅读(0)
扫一扫,手机访问
startsWith方法:
注解:startsWith() 方法用于检测字符串是否以指定的前缀开始。
public class StartWith{
public static void main(String[] args){
String id[]= {"53011198902280308","52011198711038269","53011197701328291"};
int number = 0;
System.out.println("符合条件的字符串有");
for(int i=0;i<id.length;i++) {
if(id[i].startsWith("530") == true) {
number++;
System.out.println(id[i]);
}
}
System.out.println("前面3个字符为‘530'的身份证有:"+number+"个");
}
}运行结果:
符合条件的字符串有
53011198902280308
53011197701328291
前面3个字符为‘530'的身份证有:2个
售后无忧
立即购买>office旗舰店
售后无忧
立即购买>office旗舰店
售后无忧
立即购买>office旗舰店
售后无忧
立即购买>office旗舰店
正版软件
正版软件
正版软件
正版软件
正版软件
1
2
3
7
9