Home Tutorial Java Core Java split string example

 
 

Java split string example
Posted on: January 14, 2011 at 12:00 AM
Advertisement
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
Advertisement

Related Tags for Java split string example:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: January 14, 2011

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com