集册 Java实例教程 Java字符串拆分

Java字符串拆分

欢马劈雪     最近更新时间:2020-01-02 10:19:05

421
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
Java字符串拆分
/** 来自 nowjava - 时  代  Java**/


public class Main {

 

  public static void main(String args[]){

  String str = "one-two-three";

  String[] temp;

 

  String delimiter = "-";

  temp = str.split(delimiter);

  for(int i =0; i < temp.length ; i++)

    System.out.println(temp[i]);

 

  System.out.println("");
  /**
  时 代 J a v a 公 众 号 - nowjava.com
  **/

  str = "one.two.three";

  delimiter = "\\.";

  temp = str.split(delimiter);

  for(int i =0; i < temp.length ; i++)

    System.out.println(temp[i]);

 

  System.out.println(""
展开阅读全文