Java Strings

Test your knowledge of Java String and StringBuffer methods including concatenation, comparison, searching, and manipulation operations.

17 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

Which of the following methods is used in Java to concatenate two strings?

  1. replace()
  2. trim()
  3. concat()
  4. substring()
Question 2 Multiple Choice (Single Answer)

Which of the following methods converts data from its internal format into a human readable form?

  1. toLowerCase()
  2. valueOf()
  3. toUpperCase()
  4. length()
Question 3 Multiple Choice (Single Answer)

The ____________ replaces all occurrences of one character in the invoking string with another character.

  1. replace() method
  2. length() method
  3. trim() method
  4. None of these
Question 4 Multiple Choice (Single Answer)

The______________ returns a copy of the invoking string from which any leading and trailing whitespace has been removed.

  1. length() method
  2. trim() method
  3. charAt() method
  4. none of these
Question 5 Multiple Choice (Single Answer)

The value of a single character can be obtained from a StringBuffer by using _____________ method.

  1. ensureCapacity()
  2. replace()
  3. charAt()
  4. none of these
Question 6 Multiple Choice (Single Answer)

Which method is used to convert all the characters in a string from uppercase to lowercase?

  1. toLowerCase()
  2. toUpperCase()
  3. concat()
  4. setLength()
Question 7 Multiple Choice (Single Answer)

Which method is used to set the size of the buffer?

  1. charAt()
  2. setLength()
  3. ensureCapacity()
  4. valueOf()
Question 8 Multiple Choice (Single Answer)

Which method is used to reverse the characters within a StringBuffer() object?

  1. ensureCapacity()
  2. reverse()
  3. append()
  4. concat()
Question 9 Multiple Choice (Single Answer)

Which method inserts one string into another and is overloaded to accept value of all the simple types, plus Strings & Objects?

  1. insert()
  2. reverse()
  3. delete()
  4. getChars()
Question 10 Multiple Choice (Single Answer)

The__________ method deletes a sequence of characters from the invoking object.

  1. replace()
  2. length()
  3. delete()
  4. none of these
Question 11 Multiple Choice (Single Answer)

Which method is used to copy a substring of a StringBuffer into an array?

  1. getChars()
  2. append()
  3. setLength()
  4. insert()
Question 12 Multiple Choice (Single Answer)

To compare two strings for equality _____________ method is used.

  1. equals()
  2. regionMatches()
  3. equalsIgnoreCase()
  4. reverse()
Question 13 Multiple Choice (Single Answer)

The _____________ method compares a specific region inside a string with another specific region in another string.

  1. charAt()
  2. trim()
  3. regionMatches()
  4. none of these
Question 14 Multiple Choice (Single Answer)

The_________ method concatenates the string representation of any other type of data to the end of the invoking StringBuffer object.

  1. concat()
  2. append()
  3. toLowerCase()
  4. none of these
Question 15 Multiple Choice (Single Answer)

Which of the following methods determines whether a given string begins with a specified string?

  1. getChars()
  2. startWith()
  3. endWith()
  4. none of these
Question 16 Multiple Choice (Single Answer)

The ___________method determines whether the string in question ends with a specified string.

  1. regionMatches()
  2. endWith()
  3. ensureCapacity()
  4. valueOf()
Question 17 Multiple Choice (Single Answer)

Which of the following searches for the first occurrence of a character or substring?

  1. indexOf()
  2. lastIndexOf()
  3. delete()
  4. none of these