Sie sind auf Seite 1von 8

STRING MCQ

1. Which of these class is superclass of String and StringBuffer class?


 A. java.util
 B. java.lang
 C. ArrayList
 D. None of the mentioned

2. Which of these operators can be used to concatenate two or more String


objects?
 A. +
 B. +=
 C. &
 D. ||

3. Which of these method of class String is used to obtain length of String


object?
 A. get()
 B. Sizeof()
 C. lengthof()
 D. length()
4. Which of these method of class String is used to extract a single
character from a String object?
 A. CHARAT()
 B. charat()
 C. charAt()
 D. ChatAt()

5. Which of these constructors is used to create an empty String object?


 A. String()
 B. String(void)
 C. String(0)
 D. None of the mentioned

6. Which of these is an oncorrect statement?


 A. String objects are immutable, they cannot be changed.
 B. String object can point to some other reference of String variable.
 C. StringBuffer class is used to store string in a buffer for later use.
 D. None of the mentioned

7. Which of these method of class String is used to compare two String


objects for their equality?
 A. equals()
 B. Equals()
 C. isequal()
 D. Isequal()

8. Which of these methods is used to compare a specific region inside a


string with another specific region in another string?
 A. regionMatch()
 B. match()
 C. RegionMatches()
 D. regionMatches()

9. Which of these method of class String is used to check weather a given


object starts with a particular string literal?
 A. startsWith()
 B. endsWith()
 C. Starts()
 D. ends()

10. What is the value returned by unction compareTo() if the invoking string
is less than the string compared?
 A. zero
 B. value less than zero
 C. value greater than zero
 D. None of the mentioned
11. Which of these data type value is returned by equals() method of String
class?
 A. char
 B. int
 C. boolean
 D. All of the mentioned
12. Which of these method of class String is used to extract a substring from
a String object?
 A. substring()
 B. Substring()
 C. SubString()
 D. None of the mentioned
13.What will s2 contain after following lines of code?
String s1 = “one”;
String s2 = s1.concat(“two”)
 A. one
 B. two
 C. onetwo
 D. twoone

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

15. What is the value returned by function compareTo() if the invoking string
is less than the string compared?
 A. zero
 B. value less than zero
 C. value greater than zero
 D. None of the mentioned
16. Which of the following statement is correct?
 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.

17. Which of these class is used to create an object whose character


sequence is mutable?
 A. String()
 B. StringBuffer()
 C. Both of the mentioned
 D. None of the mentioned
18. Which of these method of class StringBuffer is used to concatenate the
string representation to the end of invoking string?
 A. concat()
 B. append()
 C. join()
 D. concatenate()

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

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


StringBuffer s new StringBuffer(“Hello”);
s.deleteCharAt(0);
 A. Hell
 B. ello
 C. Hel
 D. llo
1. B
2. A
3. D
4. C
5. A
6. C
7. A
8. D
9. A
10. B
11. C
12. A
13. C
14. C
15. B
16. A
17. B
18. B
19. A
20. B

Das könnte Ihnen auch gefallen