split用法举例

来源:互联网 发布:python 远程 编辑:程序博客网 时间:2024/05/16 14:31
 

split

public String[] split(String regex)
根据给定正则表达式的匹配拆分此字符串。

该方法的作用就像是使用给定的表达式和限制参数 0 来调用两参数 split 方法。因此,所得数组中不包括结尾空字符串。

 

public class MyDemo{public static void main(String args[]){ String str="张三:90|李四:89|王五:78"; String s[]=str.split("\\|"); for(int x=0;x<str.length();x++) { String temp[] = s[x].split(":");                        System.out.println("姓名:"+temp[0]+",成绩是:"+temp[1]);          }}}