What would be the best way to split a string array in certain index to make a string matrix removing the element you split. For example, for the string array ["Good","Bad","Sad"] if i split it at 1 it would give me a string matrix that looked like this [["Good"],["Sad"]]
What would be the best way to split a string array in certain index
Share
well ivanovic’s answer explains how to simply remove one element from a string sequence with java Collection (List). And it is indeed the straightforward way to achieve that goal (removing element).
However, my understanding of OP’s question is, he gets an string array as parameter, and wants a 2-D String array to get returned. the “split-index” element should not be included in the result String[][].
Base on my understanding, I therefore add another answer:
well this is even not a java-method, but it explains how to get the result. in the example above, the result would be a 2-d array,
[[one, two, three], [five, six, seven, eight]]EDIT:
wrap it in a method is easy:
Note that error handling part is not there, e.g. pos outofbound handling, NPE checking (input) etc. you could do it by yourself I believe.