packagecom.journaldev.util;importjava.util.Arrays;importjava.util.regex.Pattern;publicclassStringToArrayExample{/**
* This class shows how to convert String to String Array in Java
* @param args
*/publicstaticvoidmain(String[] args){String line ="My name is Pankaj";//using String split functionString[] words = line.split(" ");System.out.println(Arrays.toString(words));//using java.util.regex PatternPattern pattern =Pattern.compile(" ");
words = pattern.split(line);System.out.println(Arrays.toString(words));}}