Data Science. Angular 7. Machine Learning. Data Structures. Operating System. Computer Network. Compiler Design. Computer Organization. Discrete Mathematics. Ethical Hacking. Computer Graphics. The position of the argument in the argument list is decided based on the value of the integer. Till now we have observed the various conversion specifiers and the usage of them. In this last section let us check some additional miscellaneous conversions.
Your email address will not be published. Prev Java String length Method. Pankaj I love Open Source technologies and writing about my experience about them is my passion. Follow Author. Comments Jeremy Gordon Flowers says:. January 3, at am. Asim Husain says:. January 8, at am. Exception Thrown:. Skip to content. Change Language. Related Articles. Table of Contents.
Improve Article. Save Article. Returns: true if length is 0 , otherwise false Since: 1. An index ranges from 0 to length - 1. The first char value of the sequence is at index 0 , the next at index 1 , and so on, as for array indexing.
If the char value specified by the index is a surrogate , the surrogate value is returned. Specified by: charAt in interface CharSequence Parameters: index - the index of the char value. Returns: the char value at the specified index of this string.
The first char value is at index 0. Throws: IndexOutOfBoundsException - if the index argument is negative or not less than the length of this string. The index refers to char values Unicode code units and ranges from 0 to length - 1. If the char value specified at the given index is in the high-surrogate range, the following index is less than the length of this String , and the char value at the following index is in the low-surrogate range, then the supplementary code point corresponding to this surrogate pair is returned.
Otherwise, the char value at the given index is returned. Parameters: index - the index to the char values Returns: the code point value of the character at the index Throws: IndexOutOfBoundsException - if the index argument is negative or not less than the length of this string. The index refers to char values Unicode code units and ranges from 1 to length.
If the char value at index - 1 is in the low-surrogate range, index - 2 is not negative, and the char value at index - 2 is in the high-surrogate range, then the supplementary code point value of the surrogate pair is returned.
If the char value at index - 1 is an unpaired low-surrogate or a high-surrogate, the surrogate value is returned. 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. 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.
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.
0コメント