Removing all empty elements from an character array

后端 未结 5 2017
面向向阳花
面向向阳花 2021-01-15 11:07

I have a character array that can hold maximum 50000 characters at a time. Contents of this array are coming through socket connections. However it is not guaranteed that th

5条回答
  •  遥遥无期
    2021-01-15 11:47

    I would suggest converting the array to a string and using the replaceAll and trim functions to remove the empty elements.

    String bufferString = new String(buffer).trim().replaceAll(" ", "");
    

    This does not require any additional libraries.

提交回复
热议问题