Wednesday 13 March 2013

Methods length()


Methods
length()

Declaration:
public int length()

charAt(int)

Description:
Returns the length of this string. The length is equal to the number of 16-bit Unicode characters in the
string.
Returns: the length of the sequence of characters represented by this object.
charAt(int)
Declaration:
public char charAt(int index)
Description:
Returns the character at the specified index. An index ranges from 0 to length() - 1. The first
character of the sequence is at index 0, the next at index 1, and so on, as for array indexing.
Parameters:
index - the index of the character.
Returns: the character at the specified index of this string. The first character is at index 0.
Throws:
IndexOutOfBoundsException - if the index argument is negative or not less than the length of
this string.
getChars(int, int, char[], int)
Declaration:
public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)
Description:
Copies characters from this string into the destination character array.
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). The characters are copied into
the subarray of dst starting at index dstBegin and ending at index:
dstbegin + (srcEnd-srcBegin) - 1
Parameters:
srcBegin - index of the first character in the string to copy.
srcEnd - index after the last character in the string to copy.
dst - the destination array.
dstBegin - the start offset in the destination array.
Throws:
IndexOutOfBoundsException - If any of the following is true:
• srcBegin is negative.
• srcBegin is greater than srcEnd
• srcEnd is greater than the length of this string
• dstBegin is negative
• dstBegin+(srcEnd-srcBegin) is larger than dst.length
NullPointerException - if dst is null

getBytes(String)
Declaration:
public byte[] getBytes(java.lang.String enc)
throws UnsupportedEncodingException
Description:
Convert this String into bytes according to the specified character encoding, storing the result into a new
byte array.
Parameters:
enc - A character-encoding name
Returns: The resultant byte array
Throws:
java.io.UnsupportedEncodingException - If the named encoding is not supported
Since: JDK1.1
getBytes()
Declaration:
public byte[] getBytes()
Description:
Convert this String into bytes according to the platform’s default character encoding, storing the result
into a new byte array.
Returns: the resultant byte array.
Since: JDK1.1
equals(Object)
Declaration:
public boolean equals(java.lang.Object anObject)
Description:
Compares this string to the specified object. 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.
Overrides: equals in class Object
Parameters:
anObject - the object to compare this String against.
Returns: true if the String are equal; false otherwise.
See Also: compareTo(String), equalsIgnoreCase(String)
equalsIgnoreCase(String)
Declaration:
public boolean equalsIgnoreCase(java.lang.String anotherString)
Description:
Compares this String to another String, ignoring case considerations. 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.
Two characters c1 and c2 are considered the same, ignoring case if at least one of the following is true:

compareTo(String)

• The two characters are the same (as compared by the == operator).
• Applying the method Character.toUpperCase(char) to each character produces the same
result.
• Applying the method Character.toLowerCase(char) to each character produces the same
result.
Parameters:
anotherString - the String to compare this String against.
Returns: true if the argument is not null and the Strings are equal, ignoring case; false otherwise.
See Also: equals(Object), Character.toLowerCase(char),
Character.toUpperCase(char)
compareTo(String)
Declaration:
public int compareTo(java.lang.String anotherString)
Description:
Compares two strings lexicographically. 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. If they
have different characters at one or more index positions, let k be the smallest such index; then the string
whose character at position k has the smaller value, as determined by using the < operator, lexicographically
precedes the other string. In this case, compareTo returns the difference of the two character values at
position k in the two string —- that is, the value:
this.charAt(k)-anotherString.charAt(k)
If there is no index position at which they differ, then the shorter string lexicographically precedes the
longer string. In this case, compareTo returns the difference of the lengths of the strings —- that is, the
value:
this.length()-anotherString.length()
Parameters:
anotherString - the String to be compared.
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.
Throws:
NullPointerException - if anotherString is null.

regionMatches(boolean, int, String, int, int)
Declaration:
public boolean regionMatches(boolean ignoreCase, int toffset, java.lang.String other,
int ooffset, int len)
Description:
Tests if two string regions are equal.
A substring of this String object is compared to a substring of the argument other. The result is true
if these substrings represent character sequences that are the same, ignoring case if and only if
ignoreCase is true. 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.
• ooffset is negative.
• toffset+len is greater than the length of this String object.
• ooffset+len is greater than the length of the other argument.
• There is some nonnegative integer k less than len such that:
this.charAt(toffset+k) != other.charAt(ooffset+k)
• ignoreCase is true and there is some nonnegative integer k less than len such that:
Character.toLowerCase(this.charAt(toffset+k)) !=
Character.toLowerCase(other.charAt(ooffset+k))
and:
Character.toUpperCase(this.charAt(toffset+k)) !=
Character.toUpperCase(other.charAt(ooffset+k))
Parameters:
ignoreCase - if true, ignore case when comparing characters.
toffset - the starting offset of the subregion in this string.
other - the string argument.
ooffset - the starting offset of the subregion in the string argument.
len - the number of characters to compare.
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.
startsWith(String, int)
Declaration:
public boolean startsWith(java.lang.String prefix, int toffset)
Description:
Tests if this string starts with the specified prefix beginning at the specified index.
Parameters:
prefix - the prefix.
toffset - where to begin looking in the string.





No comments:

Post a Comment