Java String Split - Java Language Basics

Java examples for Language Basics:String

Description

Java String Split

Demo Code


public class Main {
 
  public static void main(String args[]){
  String str = "one-two-three";
  String[] temp;// w ww.  ja v  a 2  s. c  om
 
  String delimiter = "-";
  temp = str.split(delimiter);
  for(int i =0; i < temp.length ; i++)
    System.out.println(temp[i]);
 
  System.out.println("");
  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("");
  temp = str.split(delimiter,2);
  for(int i =0; i < temp.length ; i++)
    System.out.println(temp[i]);
  }
}

Result


Related Tutorials