Split Demo using RegularExpression

This Example describe the way to Split a String using Regularexpression.

Split Demo using RegularExpression

Split Demo using RegularExpression

     

This Example describe the way to Split a String using Regularexpression. The steps involved in splitting a String are described below:-

 String text = "For some college -Presidents want law-revisited saying age limit-has not curbed-that problems on campuses":-This is the String to which we are splitting.

String Splitpoint = "-":-Point where the string is to be splitted.

 
 

SplitString.java

import java.util.*;
public class SplitString {
  public static void main(String[] args) {

String text = 
"For some college -Presidents want law-revisited" +
 
" saying age limit-has not curbed-that problems on campuses";
System.out.println("==========STRING BEFORE SPLITTING IS:=");

 System.out.println(text);
  new SplitString().split(text);
  }
  public void split(String Text) {
  String token[] null;
  String Splitpoint = "-";
  token = Text.split(Splitpoint);
 System.out.println("==========SPLITTED STRING IS:=======");

  for (int i = 0; i < token.length; i++) {
  System.out.println(token[i]);
  }
 System.out.println("==================================");

  }
}

Output of the program:-
==========STRING BEFORE SPLITTING IS:==========
For some college -Presidents want law-revisited saying
age limit-has not curbed-that problems on campuses
==========SPLITTED STRING IS:==========
For some college
Presidents want law
revisited saying age limit
has not curbed
that problems on campuses
========================================
Download Source Code