About 276,000 results
Open links in new tab
  1. java - Trim a string based on the string length - Stack Overflow

    Dec 14, 2011 · By ignoring this, we might trim the string to fewer than 10 code points, or (worse) truncate it in the middle of a surrogate pair. On the other hand, String.length() is not the correct …

  2. How to correctly compute the length of a String in Java?

    The normal model of Java string length String.length() is specified as returning the number of char values ("code units") in the String. That is the most generally useful definition of the length of a …

  3. Java - Create a new String instance with specified length and filled ...

    Nov 26, 2009 · Sometimes you want to create a new string with a specified length, and with a default character filling the entire string. ie, it would be cool if you could do new String(10, '*') …

  4. java - Generate fixed length Strings filled with whitespaces - Stack ...

    I need to produce fixed length string to generate a character position based file. The missing characters must be filled with space character. As an example, the field CITY has a fixed …

  5. java - When to use .length vs .length () - Stack Overflow

    But when you are using people[i].length(), you are accessing the string at that position of the array, and getting the length of the string, therefore using the .length() method in the String …

  6. How can I pad a String in Java? - Stack Overflow

    Dec 2, 2016 · Is there some easy way to pad Strings in Java? Seems like something that should be in some StringUtil-like API, but I can't find anything that does this.

  7. arrays - length and length () in Java - Stack Overflow

    Dec 27, 2009 · Why do we have the length of an array as an attribute, array.length, and for String we have a method, str.length()? Is there some reason?

  8. How to sort String array by length using Arrays.sort ()

    Mar 8, 2016 · I am trying to sort an array of strings according to their length using Arrays.sort(), but this sorts the strings lexicographically rather than by length. Here is my code: S = "No one …

  9. String's Maximum length in Java - calling length () method

    May 3, 2009 · Considering the String class' length method returns an int, the maximum length that would be returned by the method would be Integer.MAX_VALUE, which is 2^31 - 1 (or …

  10. Cut Java String at a number of character - Stack Overflow

    I would like to cut a Java String when this String length is > 50, and add "..." at the end of the string. Example : I have the following Java String : String str = "abcdefghijklmnopqrtuvwxyz"; I