Java Strings
Test your knowledge of Java String and StringBuffer methods including concatenation, comparison, searching, and manipulation operations.
Questions
Which of the following methods is used in Java to concatenate two strings?
- replace()
- trim()
- concat()
- substring()
Which of the following methods converts data from its internal format into a human readable form?
- toLowerCase()
- valueOf()
- toUpperCase()
- length()
The ____________ replaces all occurrences of one character in the invoking string with another character.
- replace() method
- length() method
- trim() method
- None of these
The______________ returns a copy of the invoking string from which any leading and trailing whitespace has been removed.
- length() method
- trim() method
- charAt() method
- none of these
The value of a single character can be obtained from a StringBuffer by using _____________ method.
- ensureCapacity()
- replace()
- charAt()
- none of these
Which method is used to convert all the characters in a string from uppercase to lowercase?
- toLowerCase()
- toUpperCase()
- concat()
- setLength()
Which method is used to set the size of the buffer?
- charAt()
- setLength()
- ensureCapacity()
- valueOf()
Which method is used to reverse the characters within a StringBuffer() object?
- ensureCapacity()
- reverse()
- append()
- concat()
Which method inserts one string into another and is overloaded to accept value of all the simple types, plus Strings & Objects?
- insert()
- reverse()
- delete()
- getChars()
The__________ method deletes a sequence of characters from the invoking object.
- replace()
- length()
- delete()
- none of these
Which method is used to copy a substring of a StringBuffer into an array?
- getChars()
- append()
- setLength()
- insert()
To compare two strings for equality _____________ method is used.
- equals()
- regionMatches()
- equalsIgnoreCase()
- reverse()
The _____________ method compares a specific region inside a string with another specific region in another string.
- charAt()
- trim()
- regionMatches()
- none of these
The_________ method concatenates the string representation of any other type of data to the end of the invoking StringBuffer object.
- concat()
- append()
- toLowerCase()
- none of these
Which of the following methods determines whether a given string begins with a specified string?
- getChars()
- startWith()
- endWith()
- none of these
The ___________method determines whether the string in question ends with a specified string.
- regionMatches()
- endWith()
- ensureCapacity()
- valueOf()
Which of the following searches for the first occurrence of a character or substring?
- indexOf()
- lastIndexOf()
- delete()
- none of these