Ch. 17-18-19 Flashcards
compareTo()
- return type
- definition
- explanation of the format
- static or not
- returns an int
- compares the ASCII values of any object, returning a negative int if the object is less that the compared value, a positive if it is more, and zero if they are equal.
- s.compareTo(“this is what I compare to”);
- not static
what is the version of compareTo() that is not case sensitive
.compareToIgnoreCase
how many versions of indexOf are there? What do they all do if the search comes up empty?
6, and they all would return -1
indexOf(String str)
- return type
- definition
- explanation of the format
- static or not
- returns an int
- returns the index of the segment within the String
- s.indexOf(“thing i want index of”);
- not static
indexOf(String s, int from)
does the same thing as indexOf(String s) but starts checking from the index of the int parameter (from).
indexOf(char ch)
searches from left to right for the first occurrence of the char.
indexOf(int ascii)
similar to ch, except instead of giving a char it gives the ascii code of a char
indexOf(char ch, int from)
starting from the index ‘from’, checking for char ch.
indexOf(int ascii, int from)
similar to indexOf(char ch, int from) except the char is gotten from the character’s ascii code.
lastIndexOf()
with six versions, it is exactly the same as indexOf except it starts searching right to left rather than left to right
charAt(int indx)
- return type
- definition
- explanation of the format
- static or not
- returns a char
- returns the char that is at the specified index
- s.charAt(3); This returns the character that is at index 3 of the string s.
- not static
replace(char old, char new)
replaces all occurrences of the old char with the new char
replace(String old, String new)
replaces all occurrences of the old string with the new string
s.trim()
not static
removes the whitespace from both ENDS of the String while leaving the interior whitespaces alone.
contains(String ss)
- return type
- definition
- explanation of the format
- static or not
- returns a boolean
- returns true if the String contains the String ss
- “something”.contains(“some”); or s.contains(“hay”);
- not static
startsWith(String ss)
- return type
- definition
- explanation of the format
- static or not
- return a boolean
- returns true if the string starts with String ss.
- s.startsWith(“something”); or “something”.startsWith(“some”);
- not static
delimiters
a series of characters that separates the text presented to a scanner object into separate tokens
position of scanner
always BETWEEN two characters (like a cursor) never on top of one
what is the default delimeter
whitespace
sc.next()
moves position of scanner to right and returns the next complete token.