Tuesday, April 18, 2017

java split string

Question
What regex pattern would need I to pass to the java.lang.String.split() method to split a String into an Array of substrings using all whitespace characters (' ', '\t', '\n', etc.) as delimiters?
Answer
myString.split("\\s+");
 ------------------------------------
String[] words=s1.split("\\s");//splits the string based on whitespace  

No comments:

Post a Comment