Top 20 MCQ Questions On Strings And Vectors In Java

This set of multiple choice question includes collection of top 20 MCQ questions on most commonly used string methods in Java, commonly used StringBuffer methods, vector class and wrapper classes. It also includes MCQs on different methods of wrapper classes like constructor methods, typeValue() method, String() method, valueOf() method and parsing method along with enumerated types, annotations, auto boxing and unboxing features in Java.

1. What is the output of the following code?
     String S;
     System.Out.println(“S =  “+S);
A) null
B) error
C) = S
D) S =

2. Which of the following are the wrapper classes?
i) Random           ii) Byte                iii) Vector            
iv) Integer           v) Short
A) i, ii and iv only
B) ii, iii and v only
C) ii, iv and v only
D) i, ii and iii only

3. Given the code
String S1=”yes”
String S2=”yes”
String S3=new String(S1);
Which of the following would equal to True?
i) S1 = = S2                ii) S1 = S2
iii) S3 = = S1             iv) S1.equals(S2)
A) i and ii only
B) ii and iii only
C) ii and iv only
D) i and iv only

4. Which of the following method call returns negative if S1<S2, positive if S1>S2 and zero if S1 is equal to S2.
A) S2.compareTo(S1)
B) S1.compareTo(S2)
C) compare S1 To S2

5. The method ……………………………. sets the length of the string S1 to n. If n<S1.length() S1 is truncated. If n>S1.length() zeros are added to S1.
A) S1.setLength(n)
B) S1.AddLength(n)
C) S1.LengthAdd(n)
D) S1.Append(n)

6. Java compiler provides restrictions to perform which of the following conversions.
i) Convert from null type to any primitive type
ii) Convert to the null type other than the identify conversion.
iii) Convert from any class type C to any array type if C is not object.
A) i and ii only
B) ii and iii only
C) i and iii only
D) All i, ii and iii

7. We can use …………………….. feature to convert primitive data types to wrapper class types automatically.
A) auto boxing
B) unboxing
C) annotations
D) Both A and B

8. Which of the following is/are the advantages over arrays.
i) It is convenient to use vectors to store objects
ii) A vector can be used to store a list of objects that may vary in size
iii) We can add and delete objects from the list as and when required
A) i and ii only
B) ii and iii only
C) i and iii only
D) All i, ii and iii

9. Primitive data types may be converted into object types by using the contained in the java.lang types by using the ………………… contained in the java.lang package.
A) parsing methods
B) wrapper classes
C) constructor methods
D) abstract classes

10. You can convert sting objects to numeric objects using the static method ……………..
A) String()
B) valueOf()
C) typeValue()
D) getValue()

11. We can convert numeric string to primitive number using …………………….
A) parsing methods
B) wrapper classes
C) constructor methods
D) abstract classes

12. …………………. in wrapper classes are used to convert primitive numbers to object numbers.
A) Constructor Methods
B) String() Method
C) typeValue() Method
D) Parsing Method

13. The ………………………. method is used to convert object numbers to primitive numbers.
A) Constructor
B) String()
C) typeValue()
D) Parsing

14. State whether the following statements about the advantages of enumerated types are True or False.
i) Enumerated types are compile-time type safety
ii) We can use the enum keyword in switch statements
A) True, False
B) False, True
C) True, True
D) False, False

15.  ……………………….. feature merge additional Java elements with the programming elements, such as classes, methods, parameters, local variables, packages and fields.
A) Auto boxing
B) Unboxing
C) Annotations
D) Both A and B

16. If you need to extract more than one character at a time you can use the ………….
A) CharAt()
B) getChars()
C) MultipleChar()
D) getBytes()

17. Which of the following is/are the classes that implement the AnnotatedElement interface
i) java.lang.reflect.accessibleobject
ii) java.lang.class
iii) java.lang.package
iv) java.lang.reflect.field
A) i ii and iii only
B) ii, iii and iv only
C) i, iii and iv only
D) All i, ii, iii and iv

18. …………………….. method is used to remove any leading or trailing white space that may have inadvertently been entered by the user.
A) trim()
B) remove()
C) replace()
D) length()

19. The …………………………. method converts data from its internal format into a human-readable form.
A) convert()
B) valueOf()
C) compare()
D) getValue()

20. The …………………… method concatenates the string representation of any other type of data to the end of invoking stringBuffer object.
A) append()
B) concat()
C) setLength()
D) convert()


1. A) null
2. C) ii, iv and v only
3. D) i and iv only
4. B) S1.compareTo(S2)
5. A) S1.setLength(n)
6. D) All i, ii and iii
7. D) Both A and B
8. D) All i, ii and iii
9. B) wrapper classes
10. B) valueOf()
11. A) parsing methods
12. A) Constructor Methods
13. C) typeValue()
14. C) True, True
15. C) Annotations 
16. B) getChars()
17. D) All i, ii, iii and iv
18. A) trim()
19. B) valueOf()
20. A) append()

Read Next:MCQ On Inheritance, Package And Interface In Java

Read More:  Java MCQ Questions

About shuseel

Shuseel Baral is a web programmer and the founder of InfoTechSite has over 5 years of experience in software development, internet, SEO, blogging and marketing digital products and services is passionate about exceeding your expectations.

Leave a Comment

Your email address will not be published. Required fields are marked *