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.