[java] Trim a string based on the string length