About this 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? How did java split on whitespace?
: 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? How did java split on whitespace?
Log in to share your answer and help other learners.
Log in to answerBest Answer · By JanBask DevOps Expert
Answered on Jul 18, 2021
For split on whitespace in JavaTry this syntax:
myString.split("\s+");This combines all-white spaces as a delimiter.
So if you have the string:
"Hello[space][tab]World"This will yield the strings "Hello" and "World" and eliminate the space among the [space] and the [tab].
Note: The backslash should be avoided because Java would first try to avoid the string to a special character, and transfer that to be parsed. What you want, is the literal "s", which means, you need to pass "\s". It can become a bit complicated.
The \s is equivalent to [ \t\n\x0B\f\r]Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.
Most-read guides across JanBask
Common DevOps interview questions, answered
Guides, tips and career advice on DevOps from JanBask experts.
DevOps How to Become a DevOps Engineers: Learning Path, Critical skills & More
Looking for answer to how to become a DevOps engineer in 2025? Here is the detailed article about DevOps career path, DevOps…
DevOps Top 50+ Jenkins Interview Questions And Answers For 2025
Here are the Top 50 Jenkins interview questions frequently asked in top MNCs which will help you land an ideal job! These…
DevOps Best 37 DevOps Tools To Learn And Master In 2025: Docker, Git & More
Want to know what are Devops tools and their uses? Or looking for the best DevOps list for automation, monitoring, & development?…
DevOps DevOps Engineer Job Description: Roles and Responsibilities [2025 Updated]
Discover the essential roles and responsibilities of a DevOps Engineer by exploring the detailed DevOps job description, and…