String/Builder/Array/List methods Flashcards
charAt
(int)
returns char at index int.
String/StringBuilder.
String.indexOf
(int(char) | String, ~ | int)
returns first matching index of char or string, -1 otherwise. Second int can be used to set starting point of search.
substring
(int, ~ | int )
returns substring from index first int to either the end of the string or point second int, exclusive.
String/StringBuilder.
trim
()
returns string with surrounding white space (new lines, spaces, tabs) removed.
String.
String.replace
(char, char)|(string, string)
returns string with second char or string wherever first char or string is found.
length
()
returns the natural length of the string.
String/StringBuilder.
startsWith
(String, ~ | int)
returns boolean telling whether or not the string begins with the first string either at the beginning or at the index second int.
String.
endsWith
(String)
returns boolean telling whether or not the string ends with the specified string, starting from the bottom now we’re here.
String.
String Operators
+, +=, ==, !=. + may add numbers before strings.
StringBuilder Constructors
StringBuilder() - creates empty string builder with capacity of 16.
StringBuilder(int) - creates empty string builder with capacity of int.
StringBuilder(String) - created string builder with capacity of string + 16.
append
(*)
returns and mutates StringBuilder with * attached at the end. * can literally be anything. If it is an object whose class has not overridden toString(), classname@hashtag string will be used.
StringBuilder.
insert
(int, *) | (int, String | StringBuilder | char[], int, int)
returns and mutates StringBuilder with * (see append) inserted at first int index position. two ints can be added to specify a substring of the string-like second argument from index second int to the third int, exclusive if String or StringBuilder. if char[], the ints stand for starting position and length of substring.
StringBuilder.
reverse
()
returns and mutates string builder to its reverse.
StringBuilder.
StringBuilder.replace
(int, int, String)
mutates and returns StringBuilder: replaces index positions int to int exclusive with the string. There’s no problem if the second int is over the index; actually, it starts to knock off some of the StringBuilder’s characters without adding white white space.
subSequence
(int, int)
returns a string object wrapped around CharSequence reference from first index int to second, exclusive. does not mutate the string builder.
StringBuilder.