Home / CSE MCQs / JAVA MCQs :: Strings - Java

CSE MCQs :: JAVA MCQs

  1. Which of these data type value is returned by equals() method of String class?
  2. A.
    char
    B.
    int
    C.
    boolean
    D.
    All of the mentioned

  3. Which of these method of class String is used to extract a substring from a String object?
  4. A.
    substring()
    B.
    Substring()
    C.
    SubString()
    D.
    None of the mentioned

  5. What will s2 contain after following lines of code?

     String s1 = "one;

     String s2 = s1.concat("two)

  6. A.
    one
    B.
    two
    C.
    onetwo
    D.
    twoone

  7. Which of these method of class String is used to remove leading and trailing whitespaces?
  8. A.
    startsWith()
    B.
    trim()
    C.
    Trim()
    D.
    doTrim()

  9. What is the value returned by function compareTo() if the invoking string is less than the string compared?
  10. A.
    zero
    B.
    value less than zero
    C.
    value greater than zero
    D.
    None of the mentioned

  11. Which of the following statement is correct?
  12. A.
    replace() method replaces all occurrences of one character in invoking string with another character.
    B.
    replace() method replaces only first occurances of a character in invoking string with another character.
    C.
    replace() method replaces all the characters in invoking string with another character.
    D.
    replace() replace() method replaces last occurrence of a character in invoking string with another character.

  13. Which of these class is used to create an object whose character sequence is mutable?
  14. A.
    String()
    B.
    StringBuffer()
    C.
    Both of the mentioned
    D.
    None of the mentioned

  15. Which of these method of class StringBuffer is used to concatenate the string representation to the end of invoking string?
  16. A.
    concat()
    B.
    append()
    C.
    join()
    D.
    concatenate()

  17. Which of these method of class StringBuffer is used to find the length of current character sequence?
  18. A.
    length()
    B.
    Length()
    C.
    capacity()
    D.
    Capacity()

  19. What is the string contained in s after following lines of code?

     StringBuffer s new StringBuffer("Hello);

     s.deleteCharAt(0);

  20. A.
    Hell
    B.
    ello
    C.
    Hel
    D.
    llo