Use the Split method when the substrings you want are separated by a known delimiting character (or characters) . Regular expressions are useful when the string conforms to a fixed pattern. Use the IndexOf and Substring methods in conjunction when you don’t want to extract all of the substrings in a string.
Read moreHow Use trim and split in Java?
To remove extra spaces before and/or after the delimiter, we can perform split and trim using regex: String[] splitted = input. trim(). split(“\\s*,\\s*”);
Read moreWhat is split () in Java?
Java String split() The split() method divides the string at the specified regex and returns an array of substrings .
Read more