Directions: Use the following presentation to fill in Guided notes on String Class methods.
Notice most of them are non-static! So, they will be
called with a [Link]()!
[Link]
Method Header Description of what it does Examples of use:
it gets a character from a string. it takes an [Link](0);
public char charAt(int index) index number from a string and returns the
character
it determines if a sequence of characters can [Link](“e”);
be found and returns true or false
public boolean contains(CharSequence sequence)
it returns the length of the string in [Link]();
characters. it returns an int
public int length()
it returns the index of where a substring [Link](“anny”);
within a string can be found. if the substring
public int indexOf(String str) is not found, -1 will be returned [Link](“Danny”, 7); will start 7 characters over and
evaluate then
it goes to the index and then evaluates if [Link](“Danny”, 7);
there is a substring. returns the index where
public int indexOf(String str, int fromIndex) there is
returns a new string after taking an integer [Link](2);
input. It returns everything after the starting
public String substring(int beginIndex) integer.
returns a new string after taking in a starting [Link](1, 3);
integer and an ending integer. The ending is
public String substring(int beginIndex, int endIndex) exclusive. start is inclusive.
it changes all the characters in the string to [Link]();
all upper case
public String toLowerCase()
it changes all the characters in the string to [Link]();
all lower case
public String toUpperCase()
returns a copy of the string without the [Link]()
leading and trailing white spaces
public String trim()
it concatenates or connects a string to the [Link](b);
end of another string
public String concat(String str)
it compares the content of 2 strings. it [Link]();
returns true or false
public boolean equals(Object anObject)
it compares two strings and ignores if [Link](str2);
anything is uppercase or lowercase. returns
public boolean equalsIgnoreCase(Object anObject) true or false
it returns a new string with some or all REPLACE(“w3resource”, “ur”, “r”
matches of a pattern replaced by a
public String replacement
replace(CharSequence target, CharSequence replac
ement)
replaces all occurrences of string a with the favorite_treachers.replaceAll(“Grey”, “Gray”);
string replacement finds all values of grey and replaces them with gray
public String
replaceAll(CharSequence target, CharSequence repl
acement)
public int compareTo(String str) it takes in a string and returns a negative “apples”.compareTo(“oranges”);
number if str1 comes before str2, 0 if str1
equals str2, and a positive number if str1
comes after str2 in the dictionary. It is case
sensitive.
if different characters are found, the
difference between the unicode values of
the characters is returned.
if no difference is found and one of the
string terminates, the function will return
the difference between the lengths
Optional Extensions (Not required):
public String
replaceFirst(String regex, String replacement)
public static String
format(String format, Object... args)
public static String valueOf(…various parameters)
public String[]split(String regex)