Removing all empty elements from an character array

后端 未结 5 2016
面向向阳花
面向向阳花 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-15 11:57

    something like that should work too :

    public String readBufferUpdate() throws IOException {
      char[] buffer =new char[50000];
      is.read(buffer);
    
      return new String(ArrayUtils.removeElements(buffer, ''));
    }
    

    Doc here : http://commons.apache.org/proper/commons-lang/javadocs/api-3.1/org/apache/commons/lang3/ArrayUtils.html#removeElements(char[], char...)

提交回复
热议问题