java String split method

www.lau‮c.irutt‬om
java String split method
/**
 * @author lautturi.com
 * Java example: String split method in java
 */

import java.util.*;

public class Lautturi {

	public static void main(String[] args) {

		String str  = "Hello ,  Java World";
		//regular expression is a whitespace 
        String[] arr = str.split(" "); 
  
        for (String s : arr) 
            System.out.println(s); 
		
	}
}

output:

Hello
,

Java
World

to get rid of whitespaces around the item:

String[] arr = str.split(" +"); 
or
String[] arr = str.split("\\s+");
Created Time:2017-09-16 13:58:25  Author:lautturi