每日总结23.6.30

今日学习字符串之split()

String str = new String("13,235sdf+fnk,055s,fkd, ");
String[] newStr = str.split(",");
for(int i = 0;i < newStr.length;i++){
System.out.println(newStr[i]);
}
String[] newStr2 = str.split(",|[+]");
for(int i = 0;i < newStr2.length;i++) {
System.out.println(newStr2[i]);

输出结果:

 

String str = new String("13,235sdf+fnk,055s,fkd, ");

//第一种 limit>0
System.out.println("1111111111");
String[] newStr = str.split(",",2);
for(int i = 0;i < newStr.length;i++){
System.out.println(newStr[i]);
}

//第二种 limit=0
System.out.println("22222222222");
String[] newStr1 = str.split(",",0);
for(int i = 0;i < newStr1.length;i++){
System.out.println(newStr1[i]);
}

//第三种 limit<0
System.out.println("333333333");
String[] newStr2 = str.split(",",-1);
for(int i = 0;i < newStr2.length;i++){
System.out.println(newStr2[i]);
输出结果:

 

posted @ 2023-06-30 08:22  XieLumeng  阅读(5)  评论(0编辑  收藏  举报