time complexity of split java

Solutions on MaxInterview for time complexity of split java by the best coders in the world

showing results for - "time complexity of split java"
Mia
15 Apr 2016
18
2
3The complexity will depend on the regex that you use to do the splitting. (Yes, the argument you supply to String.split(...) is a regex!)
4
5For your example, it will be O(N) where N is the number of characters in the input String.
6
7The algorithm of split is pretty straight forward, based on an existing regex implementation. A high-level description is:
8
9Compile the regex and create a matcher
10Iterate over the string:
11Use Matcher.find(...) to find the next word boundary
12Use String.substring to extract the word
13Add word to a list of strings
14Convert the list of strings to an array of strings.