I'm implementing a game server and representing the game board as a string, take this state as an example:
String b = ", a36, a32, a26, a40, a295, a41, a49, /, , a16, a09, a68, a11, a99, ,"
I want to convert this string into the following string array:
[, a36, a32, a26, a40, a295, a41, a49, , , , a16, a09, a68, a11, a99, ]
I tried to use String.split
:
String[] bArray = b.split("/|,");
This yields:
boardArray = [, a36, a32, a26, a40, a295, a41, a49, , , , a16, a09, a68, a11, a99]
It cuts off the last " "
element in the array that I want. After modifying my code and manually adding the last element:
String[] bArray = b.split("/|,");
bArray = Arrays.copyOf(bArray, bArray.length + 1);
bArray[bArray.length - 1] = "";
This gives me the correct result, but this solution is inefficient. Does anyone have an idea how to do this more cleanly?