title: Java Serial port string read [Determine string length]
body: <p>I am reading variable string from com port. Highest length of the string is 24. If I read string lower than that, for example it read 10 length string but still whenever I am measuring the length it always give 24. How to remove extra spaces if it is lower than highest length.</p>
  
  <pre><code>        serialPort.openPort();//Open serial port
          serialPort.setParams(9600, 8, 1, 0);//Set params.
          byte[] buffer = serialPort.readBytes(24);//Read 10 bytes from serial port
          String str = new String(buffer);
          int t= str.length();
          System.out.println(t);
  </code></pre>