Wednesday 13 March 2013

lastIndexOf(int, int)


lastIndexOf(int, int)


Description:
Returns the index within this string of the last occurrence of the specified character. That is, the index
returned is the largest value k such that:
this.charAt(k) == ch
is true. The String is searched backwards starting at the last character.
Parameters:
ch - a 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.
lastIndexOf(int, int)
Declaration:
public int lastIndexOf(int ch, int fromIndex)
Description:
Returns the index within this string of the last occurrence of the specified character, searching backward
starting at the specified index. That is, the index returned is the largest value k such that:
(this.charAt(k) == ch) && (k <= fromIndex)
is true.
Parameters:
ch - a character.
fromIndex - the index to start the search from. There is no restriction on the value of fromIndex.
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: -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.
indexOf(String)
Declaration:
public int indexOf(java.lang.String str)
Description:
Returns the index within this string of the first occurrence of the specified substring. The integer returned is
the smallest value k such that:
this.startsWith(str, k)
is true.
Parameters:
str - any string.
Returns: if the string argument occurs as a substring within this object, then the index of the first character
of the first such substring is returned; if it does not occur as a substring, -1 is returned.
Throws:
NullPointerException - if str is null.

indexOf(String, int)
Declaration:
public int indexOf(java.lang.String str, int fromIndex)
Description:
Returns the index within this string of the first occurrence of the specified substring, starting at the specified
index. The integer returned is the smallest value k such that:
this.startsWith(str, k) && (k >= fromIndex)
is true.
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.
Parameters:
str - the substring to search for.
fromIndex - the index to start the search from.
Returns: If the string argument occurs as a substring within this object at a starting index no smaller than
fromIndex, then the index of the first character of the first such substring is returned. If it does not
occur as a substring starting at fromIndex or beyond, -1 is returned.
Throws:
NullPointerException - if str is null
substring(int)
Declaration:
public java.lang.String substring(int beginIndex)
Description:
Returns a new string that is a substring of this string. The substring begins with the character at the specified
index and extends to the end of this string.
Examples:
“unhappy”.substring(2) returns “happy”
“Harbison”.substring(3) returns “bison”
“emptiness”.substring(9) returns “” (an empty string)
Parameters:
beginIndex - the beginning index, inclusive.
Returns: the specified substring.
Throws:
IndexOutOfBoundsException - if beginIndex is negative or larger than the length of this
String object.
substring(int, int)
Declaration:
public java.lang.String substring(int beginIndex, int endIndex)

concat(String)

Description:
Returns a new string that is a substring of this string. The substring begins at the specified beginIndex
and extends to the character at index endIndex - 1. Thus the length of the substring is endIndexbeginIndex.
Examples:
“hamburger”.substring(4, 8) returns “urge”
“smiles”.substring(1, 5) returns “mile”
Parameters:
beginIndex - the beginning index, inclusive.
endIndex - the ending index, exclusive.
Returns: the specified substring.
Throws:
IndexOutOfBoundsException - if the beginIndex is negative, or endIndex is larger than
the length of this String object, or beginIndex is larger than endIndex.
concat(String)
Declaration:
public java.lang.String concat(java.lang.String str)
Description:
Concatenates the specified string to the end of this string.
If the length of the argument string is 0, then this String object is returned. Otherwise, a new String
object is created, representing 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”.concat(“s”) returns “caress”
“to”.concat(“get”).concat(“her”) returns “together”
Parameters:
str - the String that is concatenated to the end of this String.
Returns: a string that represents the concatenation of this object’s characters followed by the string
argument’s characters.
Throws:
NullPointerException - if str is null.
replace(char, char)
Declaration:
public java.lang.String replace(char oldChar, char newChar)
Description:
Returns a new string resulting from replacing all occurrences of oldChar in this string with newChar.
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 new String object is created 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”.replace('e', 'o')
returns “mosquito in your collar”
“the war of baronets”.replace('r', 'y')
returns “the way of bayonets”
“sparring with a purple porpoise”.replace('p', 't')
returns “starring with a turtle tortoise”
“JonL”.replace('q', 'x') returns “JonL” (no change)
Parameters:
oldChar - the old character.
newChar - the new character.
Returns: a string derived from this string by replacing every occurrence of oldChar with newChar.
toLowerCase()
Declaration:
public java.lang.String toLowerCase()
Description:
Converts all of the characters in this String to lower case.
Returns: the String, converted to lowercase.
See Also: Character.toLowerCase(char), toUpperCase()
toUpperCase()
Declaration:
public java.lang.String toUpperCase()
Description:
Converts all of the characters in this String to upper case.
Returns: the String, converted to uppercase.
See Also: Character.toLowerCase(char), toUpperCase()
trim()
Declaration:
public java.lang.String trim()
Description:
Removes white space from both ends of this string.
If this String object represents an empty character sequence, or the first and last characters of character
sequence represented by this String object both have codes greater than '&#92;u0020' (the space
character), then a reference to this String object is returned.
Otherwise, if there is no character with a code greater than '&#92;u0020' in the string, then a new
String object representing an empty string is created and returned.
Otherwise, let k be the index of the first character in the string whose code is greater than '&#92;u0020',
and let m be the index of the last character in the string whose code is greater than '&#92;u0020'. A new
String object is created, 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.substring(k, m+1).



toString()

This method may be used to trim whitespace from the beginning and end of a string; in fact, it trims all
ASCII control characters as well.
Returns: this string, with white space removed from the front and end.
toString()
Declaration:
public java.lang.String toString()
Description:
This object (which is already a string!) is itself returned.
Overrides: toString in class Object
Returns: the string itself.
toCharArray()
Declaration:
public char[] toCharArray()
Description:
Converts this string to a new character array.
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.
valueOf(Object)
Declaration:
public static java.lang.String valueOf(java.lang.Object obj)
Description:
Returns the string representation of the Object argument.
Parameters:
obj - an Object.
Returns: if the argument is null, then a string equal to “null”; otherwise, the value of
obj.toString() is returned.
See Also: Object.toString()
valueOf(char[])
Declaration:
public static java.lang.String valueOf(char[] data)
Description:
Returns the string representation of the char array argument. The contents of the character array are
copied; subsequent modification of the character array does not affect the newly created string.
Parameters:
data - a char array.
Returns: a newly allocated string representing the same sequence of characters contained in the character
array argument.




No comments:

Post a Comment