Computer Science, asked by njpyhshakya5581, 11 months ago

How to Split String in Java using Regular Expression?

Answers

Answered by pandeysakshi2003
0

String class provides split() method to split String in Java, based upon any delimiter, e.g. comma, colon, space or any arbitrary method. split() method splits the string based on delimiter provided, and return a String array, which contains individual Strings. Actually, split() method takes a regular expression, which in simplest case can be a single word. split() is also overloaded method in java.lang.String class and its overloaded version take a limit parameter which is used to control how many times pattern will be applied during splitting process. if this limit is positive n, then the pattern will be applied at most n-1 times, if it's negative or zero then split operation is applied any number of time. For example, if we split String "First,Second,Third" on comma and provide limit as 2 then pattern will run one time, and split() will return String array with 2 Strings, "First" and "Second,Third".

Since this method accepts a Java regular expression, it throws PatternSyntaxException, if the syntax of the regular expression is invalid

please make me brainlist

Similar questions