Q: Java: How to convert String of ASCII to String of characters? I am sending a message from one device to another using MQTT client/broker. The message is exchanged (sent and received) between the two devices as String succesfully.
However, on the MQTT-Broker (i.e.: the server) the message characters are received as ASCII numbers within a string. 
For example if I send: 

"This is a test"

On the broker it show: 

"84,104,105,115,32,105,115,32,97,32,116,101,115,116,10"

Using Java, I need a way to convert this string of ASCII back to string on the server for further process. 
How to do that ? thanks 

A: Convert the string to a byte[] and create a new string using the byte[]
String str = "84,104,105,115,32,105,115,32,97,32,116,101,115,116,10";
String[] chars = str.split(",");
byte[] bytes = new byte[chars.length];
for (int i = 0; i < chars.length; i++) {
  bytes[i] = Byte.parseByte(chars[i]);
}
return new String(bytes);


A: You can break the string using StringTokenizer with delimiter as comma and then iterate on each of them and use Character.toString ((char) i);

A: You can use stream as well for this, if you can use java-8
String str = Stream.of("84,104,105,115,32,105,115,32,97,32,116,101,115,116,10".split(","))
        .map(ch -> (char) Integer.valueOf(ch).intValue())
        .collect(StringBuilder::new,
                StringBuilder::appendCodePoint, StringBuilder::append)
        .toString();
System.out.println(str); // This is a test

