About 84,400 results
Open links in new tab
  1. 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 …

  2. java - Limiting the number of characters in a string, and chopping …

    The solution may be java.lang.String.format("%" + maxlength + "s", string).trim(), like this:. int maxlength = 20; String longString = "Any string you want which ...

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

    Nov 26, 2009 · Some possible solutions. This creates a String with length-times '0' filled and replaces then the '0' with the charToFill (old school).

  4. java - Trim a string based on the string length - Stack Overflow

    Dec 14, 2011 · Java streams. The Java Streams facility makes this interesting, as of Java 9 and later. Interesting, but maybe not the best approach. We use code points rather than char …

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

    May 3, 2009 · This means we cannot index the 2147483648th member.So the maximum length of String in java is 2147483647. Primitive data type int is 4 bytes(32 bits) in java.As 1 bit (MSB) is …

  6. java - why string length -1 - Stack Overflow

    Jul 9, 2016 · Because java indexing arrays from 0. For example "Hello" string's length is 5. the 'H' is the 0. charachter of the "Hello" string. According to this, the 'e' charachter is int the 1. …

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

    Feb 8, 2018 · In Java, an Array stores its length separately from the structure that actually holds the data. When you create an Array, you specify its length, and that becomes a defining …

  8. Java String Limit - Stack Overflow

    Mar 31, 2013 · There is no way to limit Strings in java to a certain finite number through inbuilt features. Strings are immutable and take the value that you provide in their constructor. You …

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

    Since Java 1.5 we can use the method java.lang.String.format(String, Object...) and use printf like format. The format string "%1$15s" do the job. Where 1$ indicates the argument index, s …

  10. How to substring in java based on length? - Stack Overflow

    Oct 26, 2015 · Trimming a Java string to a given number of bytes makes no sense unless you specify the character encoding. And even if you do, it is a bit gnarly ... for variable length …

Refresh