How can we split an array of objects? For example, I have a variety of chars like this:
['H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd']
I want to split the array with the spaces seen in position 6. After breaking, the collection will look like this:
Array1 = ['H', 'e', 'l', 'l', 'o']
Array2 = ['W', 'o', 'r', 'l', 'd']
I did find a post something like this over here, but that is not in java or Kotlin.
I know I could have done it this way:
String str = TextUtils.join(",", arr);
String[] splittedString = str.split(" ");
But, I want another way if it is possible. Using this .split
method takes up a lot of memory and about 30-40 milliseconds on large arrays.
How can I do this with java or Kotlin?
List<List<Char>>
?)