String.split(Regex regex)方法


1
@Test 2 public void testStringSplid() throws Exception { 3 String yy = "122343(44,55,,6678fff"; 4 String [] xx = yy.split("[,,(]"); 5 for(int i = 0;i < xx.length;i++){ 6 System.out.println("xx["+i+"]=" +xx[i]); 7 } 8 } 9 10 11 12 xx[0]=122343 13 xx[1]=44 14 xx[2]=55 15 xx[3]= 16 xx[4]=6678fff
 1     @Test
 2     public void testStringSplid() throws Exception {
 3         String yy = "122343";
 4         String [] xx = yy.split("[,,(]");
 5         for(int i = 0;i < xx.length;i++){
 6             System.out.println("xx["+i+"]=" +xx[i]);
 7         }
 8     }
 9 
10 
11 
12 
13 xx[0]=122343

这个方法如果正则没有匹配到,会将原字符串,作为数组第0个元素返回,不会返回null

转载于:https://www.cnblogs.com/z2qfei/p/8044153.html

你可能感兴趣的:(String.split(Regex regex)方法)