I use apache kafka to publish the string message. Before publishing, message type is string array like below,
String[] msgArray = ["aaa", "bbb", "ccc"];
My kafka publishing message type is java string, so I convert this array to string with Arrays.toString(msgArray)
method. Apache Kafka publishing and consuming work well. The received message is Java String,["aaa", "bbb", "ccc"]
. But the problem is I have no idea how to convert this array type string message back to string array. Below is the part of my codes.
//record.value is array type string -> ["aaa", "bbb", "ccc"]
String[] parameters = new String[record.value().split(",").length];
int i=0;
for(String str : record.value().split(",")) {
if(i < parameters.length) {
parameters[i] = str.replace("]", "").replace("[", "");
}
i++;
}
But the result is not appropriate. Are there any arrays api which converts array type string to string array?