0% found this document useful (0 votes)
218 views8 pages

String MCQ: A. Java - Util B. Java - Lang C. Arraylist D. None of The Mentioned

The document contains 20 multiple choice questions related to String and StringBuffer classes in Java. It tests knowledge about core concepts like superclass, concatenation methods, length methods, character extraction methods, comparison methods, mutability, substring methods and more. The correct answers to each question are provided at the end.

Uploaded by

DEv Kaushal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
218 views8 pages

String MCQ: A. Java - Util B. Java - Lang C. Arraylist D. None of The Mentioned

The document contains 20 multiple choice questions related to String and StringBuffer classes in Java. It tests knowledge about core concepts like superclass, concatenation methods, length methods, character extraction methods, comparison methods, mutability, substring methods and more. The correct answers to each question are provided at the end.

Uploaded by

DEv Kaushal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy