/** * @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+");