Splitting the String Using Split Method


StringTokenizer object available in util package is used to split the String. It splits the string into tokens using spaces between them. A file is chosen using JFileChooser and is read as string readLine method of BufferedReader object. Result is displayed in JTextArea. String class has the split method that splits the string based on the regular expression mentioned in the argument and stored in array. Here string is split using #.

  • Filename:SplitTest .java

import java.io.*;
class SplitTest {
public static void main(String args[]) throws IOException {
int m;
String sr = "Good#Learning#Environment";
String [] temp;
temp = sr.split("#");
for(m=0;m<temp.length;m++) {