Home Tutorial Java Core Java split string example

 
 

Java split string example
Posted on: January 14, 2011 at 12:00 AM
This section illustrates you the use of split() method.

Java split string example

This section illustrates you the use of split() method.

The String class has provide several methods for examining the individual characters, for extracting substrings,  for comparing strings, for searching strings, for converting string to upper case and lowercase etc. The method split() is one of them. As the name suggests, this method can split the string into the given format and will return the string in the form of string array. Actually, it is based on regex expression with some characters which have a special meaning in a regex expression.

Here is the code:

class StringSplitExample {
	public static void main(String[] args) {
		String st = "Hello_World";
		String str[] = st.split("_");
		for (int i = 0; i < str.length; i++) {
			System.out.println(str[i]);
		}
	}
}

Output:

Hello
World

Related Tags for Java split string example:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.