When is length starting




















Parameters: index - the index following the code point that should be returned Returns: the Unicode code point value before the given index. Throws: IndexOutOfBoundsException - if the index argument is less than 1 or greater than the length of this string. The text range begins at the specified beginIndex and extends to the char at index endIndex - 1. Thus the length in char s of the text range is endIndex-beginIndex. Unpaired surrogates within the text range count as one code point each.

Parameters: beginIndex - the index to the first char of the text range. Returns: the number of Unicode code points in the specified text range Throws: IndexOutOfBoundsException - if the beginIndex is negative, or endIndex is larger than the length of this String , or beginIndex is larger than endIndex. Unpaired surrogates within the text range given by index and codePointOffset count as one code point each.

Parameters: index - the index to be offset codePointOffset - the offset in code points Returns: the index within this String Throws: IndexOutOfBoundsException - if index is negative or larger then the length of this String , or if codePointOffset is positive and the substring starting with index has fewer than codePointOffset code points, or if codePointOffset is negative and the substring before index has fewer than the absolute value of codePointOffset code points.

The first character to be copied is at index srcBegin ; the last character to be copied is at index srcEnd-1 thus the total number of characters to be copied is srcEnd-srcBegin.

Copies characters from this string into the destination byte array. Each byte receives the 8 low-order bits of the corresponding character. The eight high-order bits of each character are not copied and do not participate in the transfer in any way. The first character to be copied is at index srcBegin ; the last character to be copied is at index srcEnd The total number of characters to be copied is srcEnd-srcBegin.

The behavior of this method when this string cannot be encoded in the given charset is unspecified. The CharsetEncoder class should be used when more control over the encoding process is required.

This method always replaces malformed-input and unmappable-character sequences with this charset's default replacement byte array. The behavior of this method when this string cannot be encoded in the default charset is unspecified. The result is true if and only if the argument is not null and is a String object that represents the same sequence of characters as this object.

The result is true if and only if this String represents the same sequence of characters as the specified StringBuffer. This method synchronizes on the StringBuffer. Parameters: sb - The StringBuffer to compare this String against Returns: true if this String represents the same sequence of characters as the specified StringBuffer , false otherwise Since: 1.

The result is true if and only if this String represents the same sequence of char values as the specified sequence. Note that if the CharSequence is a StringBuffer then the method synchronizes on it. Parameters: cs - The sequence to compare this String against Returns: true if this String represents the same sequence of char values as the specified sequence, false otherwise Since: 1. Two strings are considered equal ignoring case if they are of the same length and corresponding characters in the two strings are equal ignoring case.

The comparison is based on the Unicode value of each character in the strings. The character sequence represented by this String object is compared lexicographically to the character sequence represented by the argument string. The result is a negative integer if this String object lexicographically precedes the argument string. The result is a positive integer if this String object lexicographically follows the argument string. The result is zero if the strings are equal; compareTo returns 0 exactly when the equals Object method would return true.

This is the definition of lexicographic ordering. If two strings are different, then either they have different characters at some index that is a valid index for both strings, or their lengths are different, or both. In this case, compareTo returns the difference of the two character values at position k in the two string -- that is, the value: this. In this case, compareTo returns the difference of the lengths of the strings -- that is, the value: this.

Returns: the value 0 if the argument string is equal to this string; a value less than 0 if this string is lexicographically less than the string argument; and a value greater than 0 if this string is lexicographically greater than the string argument. This method returns an integer whose sign is that of calling compareTo with normalized versions of the strings where case differences have been eliminated by calling Character. Note that this method does not take locale into account, and will result in an unsatisfactory ordering for certain locales.

Parameters: str - the String to be compared. Returns: a negative integer, zero, or a positive integer as the specified String is greater than, equal to, or less than this String, ignoring case considerations. A substring of this String object is compared to a substring of the argument other.

The result is true if these substrings represent identical character sequences. The substring of this String object to be compared begins at index toffset and has length len. The substring of other to be compared begins at index ooffset and has length len. The result is false if and only if at least one of the following is true: toffset is negative. There is some nonnegative integer k less than len such that: this.

Returns: true if the specified subregion of this string exactly matches the specified subregion of the string argument; false otherwise.

The result is true if these substrings represent character sequences that are the same, ignoring case if and only if ignoreCase is true. Returns: true if the specified subregion of this string matches the specified subregion of the string argument; false otherwise. Whether the matching is exact or case insensitive depends on the ignoreCase argument.

Parameters: prefix - the prefix. Returns: true if the character sequence represented by the argument is a prefix of the substring of this object starting at index toffset ; false otherwise.

The result is false if toffset is negative or greater than the length of this String object; otherwise the result is the same as the result of the expression this.

Returns: true if the character sequence represented by the argument is a prefix of the character sequence represented by this string; false otherwise. Note also that true will be returned if the argument is an empty string or is equal to this String object as determined by the equals Object method.

Parameters: suffix - the suffix. Returns: true if the character sequence represented by the argument is a suffix of the character sequence represented by this object; false otherwise. Note that the result will be true if the argument is the empty string or is equal to this String object as determined by the equals Object method.

The hash value of the empty string is zero. Overrides: hashCode in class Object Returns: a hash code value for this object. See Also: Object. Object , System. Object indexOf public int indexOf int ch Returns the index within this string of the first occurrence of the specified character.

If a character with value ch occurs in the character sequence represented by this String object, then the index in Unicode code units of the first such occurrence is returned. For values of ch in the range from 0 to 0xFFFF inclusive , this is the smallest value k such that: this.

For other values of ch , it is the smallest value k such that: this. In either case, if no such character occurs in this string, then -1 is returned. Parameters: ch - a character Unicode code point. Returns: the index of the first occurrence of the character in the character sequence represented by this object, or -1 if the character does not occur. If a character with value ch occurs in the character sequence represented by this String object at an index no smaller than fromIndex , then the index of the first such occurrence is returned.

In either case, if no such character occurs in this string at or after position fromIndex , then -1 is returned. There is no restriction on the value of fromIndex. If it is negative, it has the same effect as if it were zero: this entire string may be searched. If it is greater than the length of this string, it has the same effect as if it were equal to the length of this string: -1 is returned.

All indices are specified in char values Unicode code units. Returns: the index of the first occurrence of the character in the character sequence represented by this object that is greater than or equal to fromIndex , or -1 if the character does not occur.

For values of ch in the range from 0 to 0xFFFF inclusive , the index in Unicode code units returned is the largest value k such that: this. For other values of ch , it is the largest value k such that: this. The String is searched backwards starting at the last character. Returns: the index of the last occurrence of the character in the character sequence represented by this object, or -1 if the character does not occur.

For values of ch in the range from 0 to 0xFFFF inclusive , the index returned is the largest value k such that: this. In either case, if no such character occurs in this string at or before position fromIndex , then -1 is returned. If it is greater than or equal to the length of this string, it has the same effect as if it were equal to one less than the length of this string: this entire string may be searched.

If it is negative, it has the same effect as if it were -1 is returned. Returns: the index of the last occurrence of the character in the character sequence represented by this object that is less than or equal to fromIndex , or -1 if the character does not occur before that point.

The returned index is the smallest value k for which: this. Parameters: str - the substring to search for. Returns: the index of the first occurrence of the specified substring, or -1 if there is no such occurrence. Returns: the index of the first occurrence of the specified substring, starting at the specified index, or -1 if there is no such occurrence. The last occurrence of the empty string "" is considered to occur at the index value this.

The returned index is the largest value k for which: this. Returns: the index of the last occurrence of the specified substring, or -1 if there is no such occurrence. Returns: the index of the last occurrence of the specified substring, searching backward from the specified index, or -1 if there is no such occurrence. The substring begins with the character at the specified index and extends to the end of this string. Examples: "unhappy". Returns: the specified substring. The substring begins at the specified beginIndex and extends to the character at index endIndex - 1.

Thus the length of the substring is endIndex-beginIndex. Examples: "hamburger". An invocation of this method of the form str. Parameters: beginIndex - the begin index, inclusive. Returns: the specified subsequence. If the length of the argument string is 0 , then this String object is returned. Otherwise, a String object is returned that represents a character sequence that is the concatenation of the character sequence represented by this String object and the character sequence represented by the argument string.

Examples: "cares". Returns: a string that represents the concatenation of this object's characters followed by the string argument's characters. If the character oldChar does not occur in the character sequence represented by this String object, then a reference to this String object is returned.

Otherwise, a String object is returned that represents a character sequence identical to the character sequence represented by this String object, except that every occurrence of oldChar is replaced by an occurrence of newChar.

Examples: "mesquite in your cellar". Returns: a string derived from this string by replacing every occurrence of oldChar with newChar. Parameters: s - the sequence to search for Returns: true if this string contains s , false otherwise Since: 1. Use Matcher. String to suppress the special meaning of these characters, if desired. Parameters: regex - the regular expression to which this string is to be matched replacement - the string to be substituted for the first match Returns: The resulting String Throws: PatternSyntaxException - if the regular expression's syntax is invalid Since: 1.

Parameters: regex - the regular expression to which this string is to be matched replacement - the string to be substituted for each match Returns: The resulting String Throws: PatternSyntaxException - if the regular expression's syntax is invalid Since: 1. The replacement proceeds from the beginning of the string to the end, for example, replacing "aa" with "b" in the string "aaa" will result in "ba" rather than "ab".

Parameters: target - The sequence of char values to be replaced replacement - The replacement sequence of char values Returns: The resulting string Since: 1. The array returned by this method contains each substring of this string that is terminated by another substring that matches the given expression or is terminated by the end of the string.

The substrings in the array are in the order in which they occur in this string. If the expression does not match any part of the input then the resulting array has just one element, namely this string. When there is a positive-width match at the beginning of this string then an empty leading substring is included at the beginning of the resulting array. A zero-width match at the beginning however never produces such empty leading substring. The limit parameter controls the number of times the pattern is applied and therefore affects the length of the resulting array.

If the limit n is greater than zero then the pattern will be applied at most n - 1 times, the array's length will be no greater than n , and the array's last entry will contain all input beyond the last matched delimiter.

If n is non-positive then the pattern will be applied as many times as possible and the array can have any length. If n is zero then the pattern will be applied as many times as possible, the array can have any length, and trailing empty strings will be discarded.

This method works as if by invoking the two-argument split method with the given expression and a limit argument of zero. Trailing empty strings are therefore not included in the resulting array. Parameters: delimiter - the delimiter that separates each element elements - the elements to join together.

Returns: a new String that is composed of the elements separated by the delimiter Throws: NullPointerException - If delimiter or elements is null Since: 1. Parameters: delimiter - a sequence of characters that is used to separate each of the elements in the resulting String elements - an Iterable that will have its elements joined together. Returns: a new String that is composed from the elements argument Throws: NullPointerException - If delimiter or elements is null Since: 1.

Since case mappings are not always char mappings, the resulting String may be a different length than the original String. This is equivalent to calling toLowerCase Locale. Note: This method is locale sensitive, and may produce unexpected results if used for strings that are intended to be interpreted locale independently. Examples are programming language identifiers, protocol keys, and HTML tags.

To obtain correct results for locale insensitive strings, use toLowerCase Locale. Returns: the String , converted to lowercase. Examples of locale-sensitive and 1:M case mappings are in the following table.

This method is equivalent to toUpperCase Locale. For instance, "title". To obtain correct results for locale insensitive strings, use toUpperCase Locale. Returns: the String , converted to uppercase. See Also: toUpperCase Locale trim public String trim Returns a string whose value is this string, with any leading and trailing whitespace removed.

A String object is returned, representing the substring of this string that begins with the character at index k and ends with the character at index m -that is, the result of this. This method may be used to trim whitespace as defined above from the beginning and end of a string.

Returns: A string whose value is this string, with any leading and trailing white space removed, or this string if it has no leading or trailing white space. Returns: a newly allocated character array whose length is the length of this string and whose contents are initialized to contain the character sequence represented by this string. The locale always used is the one returned by Locale. Parameters: format - A format string args - Arguments referenced by the format specifiers in the format string.

If there are more arguments than format specifiers, the extra arguments are ignored. The number of arguments is variable and may be zero. The behaviour on a null argument depends on the conversion. Returns: A formatted string Throws: IllegalFormatException - If a format string contains an illegal syntax, a format specifier that is incompatible with the given arguments, insufficient arguments given the format string, or other illegal conditions. For specification of all possible formatting errors, see the Details section of the formatter class specification.

Parameters: l - The locale to apply during formatting. If l is null then no localization is applied. For specification of all possible formatting errors, see the Details section of the formatter class specification Since: 1. Parameters: obj - an Object. Returns: if the argument is null , then a string equal to "null" ; otherwise, the value of obj. The contents of the character array are copied; subsequent modification of the character array does not affect the returned string.

Parameters: data - the character array. Returns: a String that contains the characters of the character array. The offset argument is the index of the first character of the subarray. The count argument specifies the length of the subarray.

The contents of the subarray are copied; subsequent modification of the character array does not affect the returned string. Returns: a String that contains the characters of the specified subarray of the character array. Parameters: b - a boolean. Returns: if the argument is true , a string equal to "true" is returned; otherwise, a string equal to "false" is returned. Parameters: c - a char.

Returns: a string of length 1 containing as its single character the argument c. The representation is exactly the one returned by the Integer. Parameters: i - an int. Returns: a string representation of the int argument.

See Also: Integer. The representation is exactly the one returned by the Long. Parameters: l - a long. Returns: a string representation of the long argument. See Also: Long. The representation is exactly the one returned by the Float. Parameters: f - a float. Returns: a string representation of the float argument.

See Also: Float. The representation is exactly the one returned by the Double. Parameters: d - a double. Returns: a string representation of the double argument. I've seen two alternative conventions used when specifying a range of indexes, e. I'm assuming that in all cases startIndex would be inclusive, and endIndex exclusive. Are there any compelling reasons to prefer one over the other when defining an API?

Improve this question. Add a comment. Active Oldest Votes. For the endIndex based one - is that an inclusive or exclusive end point? Improve this answer. How to disambiguate positional arguments Ah yes, in Smalltalk maybe, since the question is tagged language-agnostic Most use cases are equally simple using either API, but consider this one: You want to get a substring that starts at 5 and ends at the end of the string.

Using the index based version assuming it's second index is exclusive , it's as simple as: str. Marc Baumbach Marc Baumbach George Forman George Forman 4 4 silver badges 7 7 bronze badges. Sign up or log in Sign up using Google. Sign up using Facebook.

Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Podcast Explaining the semiconductor shortage, and how it might end. Does ES6 make JavaScript frameworks obsolete? Featured on Meta. Now live: A fully responsive profile. Related Hot Network Questions. Question feed. Stack Overflow works best with JavaScript enabled.



0コメント

  • 1000 / 1000