chapter 5 Flashcards
What is string concatentation?
Placing one string before the other and combining them.
What are the two ways the ways the + can be interpreted?
- If both operands are numeric, + means numeric addition.
2. If either operand is a String, + means concatenation.
What is an immutable object?
An object that cannot be changed once it is created.
Is the String type immutable?
yes.
What does String.length() return?
The number of characters in String.
What does String.charAt(1) return?
The char value at index 1 or throws IndexOutOfBoundsException - if the index argument is negative or not less than the length of this string.
What does String.indexOf() do?
Returns the index within this string of the first occurrence of the specified value, or -1.
What are the method signatures for indexOf()?
int indexOf(int ch) int indexOf(int ch, int fromIndex) int indexOf(String str) int indexOf(String str, int fromIndex)
What does the String.substring(int beginIndex) do?
Returns a new string that is a substring of this string. `
What are the method signatures for substring()?
String substring(int beginIndex) String substring(int beginIndex, int endIndex)
Is the value at the endIndex in the substring() included ?
No.
What does toLowerCase() and toUpperCase() do?
toLowerCase(): converts any uppercase characters to lowercase in the returned string.
toUpperCase(): converts any lowercase characters to uppercase in the returned string.
What does the String.equals() method do?
Returns true if the given object represents a String equivalent to this string, false otherwise.
What does the String.equalsIgnoreCase() do?
Returns true if the argument is not null and it represents an equivalent String ignoring case; false otherwise.
What does the startsWith() do?
boolean startsWith(String prefix): Returns true if the character sequence represented by the argument is a prefix of the character sequence represented by this string; false otherwise. Note also that true will be returned if the argument is an empty string or is equal to this String object as determined by the equals(Object) method.
What does the endsWith() do?
boolean endsWith(String suffix): Returns true if the character sequence represented by the argument is a suffix of the character sequence represented by this object; false otherwise. Note that the result will be true if the argument is the empty string or is equal to this String object as determined by the equals(Object) method.
What does the String.replace() do?
Replaces some value(s) with different value(s).
What are the two method signatures for replace()?
replace(char oldChar, char newChar)
replace(CharSequence target, CharSequence replacement)
What does the String.contains() do?
Returns true if and only if this string contains the specified sequence of char values.
What do the trim(), strip(), stripLeading(), and stripTrailing() methods do?
Remove whitespace from the beginning, ending or both ends of the string.
What is the difference between strip() and trim()?
strip() supports Unicode.
What does the String.intern() do?
Returns a string that has the same contents as this string, but is guaranteed to be from a pool of unique strings.
What is the StringBuilder class?
A class to create mutable strings.
What are four common StringBuilder methods?
charAt(), indexOf(), length(), and substring().