Amazing technological breakthrough possible @S-Logix pro@slogix.in

Office Address

  • #5, First Floor, 4th Street Dr. Subbarayan Nagar Kodambakkam, Chennai-600 024 Landmark : Samiyar Madam
  • pro@slogix.in
  • +91- 81240 01111

Social List

How to split the string in java?

Description

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 #.

Sample Code
  • 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++) {
System.out.println(temp[m]);
}
}
}

Screenshots

Split the string in java