C
chucky
the task: parse String on dots and create an array of portions:
input: "part1.part2.part3.part4"
output: {"part1", "part2", "part3", "part4" }
One approach is to use a loop and a dynamic structure such as
ArrayList and in every iteration find the dot and copy the portion to
the List. In the end, call List.toArray()
Another is to find the dot, store its index into a local variable and
proceed by recursion. When recursion returns, store the appropriate
portion into the resulting array at appropriate index. In the last
recursive call allocate the resulting array of Strings with the
accurate length and store the last portion into the last index.
Can the second approach be faster than the first one?
Thanks for your suggestions.
input: "part1.part2.part3.part4"
output: {"part1", "part2", "part3", "part4" }
One approach is to use a loop and a dynamic structure such as
ArrayList and in every iteration find the dot and copy the portion to
the List. In the end, call List.toArray()
Another is to find the dot, store its index into a local variable and
proceed by recursion. When recursion returns, store the appropriate
portion into the resulting array at appropriate index. In the last
recursive call allocate the resulting array of Strings with the
accurate length and store the last portion into the last index.
Can the second approach be faster than the first one?
Thanks for your suggestions.