About 152,000 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 length of a …

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

    I need to create a summary table at the end of a log with some values that are obtained inside a class. The table needs to be printed in fixed-width format. I have the code to do this already, bu...

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

    May 3, 2009 · In Java, what is the maximum size a String object may have, referring to the length() method call? I know that length() return the size of a String as a char [];

  4. 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 …

  5. In Java, for a string x, what is the runtime cost of s.length ()? Is it ...

    Jun 18, 2016 · No, the length of a java string is O (1) because java's string class stores the length as a field. The advice you've received is true of C, amongst other languages, but not java. C's …

  6. How many characters can a Java String have? - Stack Overflow

    Jul 24, 2009 · Java 9 is going to use a single byte per character for strings having only iso-latin-1 content, so such strings can have as many characters as the heap in bytes (or max array …

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

    Nov 26, 2009 · I did check the other questions; this question has its focus on solving this particular question the most efficient way. Sometimes you want to create a new string with a …

  8. java - Difference between size and length methods? - Stack Overflow

    Nov 25, 2013 · size() is a method specified in java.util.Collection, which is then inherited by every data structure in the standard library. length is a field on any array (arrays are objects, you just …

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

    Dec 27, 2009 · 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 …

  10. How do I compare strings in Java? - Stack Overflow

    Apr 2, 2013 · 124 Java have a String pool under which Java manages the memory allocation for the String objects. See String Pools in Java When you check (compare) two objects using the …