Since the argument to split()
is a regular expression, you can look for one or more spaces (" +"
) instead of just one space (" "
).
String[] array = s.split(" +");
Related Contents:
- Split string to equal length substrings in Java
- Split string with dot as delimiter
- Java string split with “.” (dot) [duplicate]
- Splitting a string at every n-th character
- Splitting on comma outside quotes
- How to split String with some separator but without removing that separator in Java? [duplicate]
- Java split is eating my characters
- Extracting pairs of words using String.split()
- Java String.split() Regex
- Split a string, at every nth position
- How to Split a mathematical expression on operators as delimiters, while keeping them in the result?
- Java replace all square brackets in a string
- How to split a string in Java
- How to split a string with any whitespace chars as delimiters
- Splitting a Java String by the pipe symbol using split(“|”)
- Split Java String by New Line
- Why in Java 8 split sometimes removes empty strings at start of result array?
- Java how to replace 2 or more spaces with single space in string and delete leading and trailing spaces
- Split string into array of character strings
- How to split a String by space
- How to extract numbers from a string and get an array of ints?
- Why does String.split need pipe delimiter to be escaped?
- How to split a string between letters and digits (or between digits and letters)?
- string to string array conversion in java
- How can non-ASCII characters be removed from a string?
- How can I use “.” as the delimiter with String.split() in java [duplicate]
- How do I convert CamelCase into human-readable names in Java?
- Get the index of a pattern in a string using regex
- Java – Best way to grab ALL Strings between two Strings? (regex?)
- Compare one String with multiple values in one expression
- The split() method in Java does not work on a dot (.) [duplicate]
- Check and extract a number from a String in Java
- Split regex to extract Strings of contiguous characters
- Extract string between two strings in java
- Use Java and RegEx to convert casing in a string
- Split string into sentences
- How do I split a string in Java?
- Replace the last part of a string
- Remove trailing zero in Java
- What is the simplest way to convert a Java string from all caps (words separated by underscores) to CamelCase (no word separators)?
- Why String.replaceAll() in java requires 4 slashes “\\\\” in regex to actually replace “\”?
- Java: Split string when an uppercase letter is found
- Java: How to split a string by a number of characters?
- Remove all empty lines
- Remove all non-“word characters” from a String in Java, leaving accented characters?
- Java split string to array [duplicate]
- Java: String split(): I want it to include the empty strings at the end [duplicate]
- Tokenizing Error: java.util.regex.PatternSyntaxException, dangling metacharacter ‘*’
- Validate a file name on Windows
- Java split String performances