How to Split String into Multiple String in Java


This example demonstrates how to split String into multiple String objects in Java.

Source Code

package com.beginner.examples;

public class JavaStringSplit {

	public static void main(String[] args) {
		
		//Create String.
		String string = "Hello World";
		String[] temString;
		
		/*
		 * To split Java String use the method split(according to given regular expression) of Java String 
		 * according to given regular expression.
		 */
		temString = string.split(" ");
		
		for(int i =0; i < temString.length ; i++) {
			System.out.println(temString[i]);
		}

	}

}

Output:

Hello
World
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments