About 708,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 Java …

  2. 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?

  3. 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 approximately 2 …

  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. 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 don't see …

  6. 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 strlen walks …

  7. java - Why is String.length () a method? - Stack Overflow

    Jan 3, 2012 · The String class was probably one of the very first classes defined for Java, ever. It's possible (and this is just speculation) that the implementation used a .length() method before final …

  8. 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, '*') and create a …

  9. 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 class. However, just …

  10. Bytes of a string in Java - Stack Overflow

    Feb 7, 2019 · In Java, if I have a String x, how can I calculate the number of bytes in that string?