Java String MCQ


Multiple choice questions on Java strings for interview preparation. This quick assessment test on Strings in Java will help you assess your Java expertise.



Instructions

Topic- Java - String

The test consists of 13 questions.

No negative marking for this test.

No Time limit

The pass percentage is 70%

The correct answer with a description will be displayed after the answer has been marked.

Submit the test to calculate your score once you are done with all the questions.

Complexity Level- Moderate




Q1: What will be the output of the below code snippet?

String s1 = "Hello";
String s2 = "John";
System.out.println(s1.concat(s2));















Q2: What will be the output of the below code snippet?

StringBuffer sb = new StringBuffer();
sb.append("Hi");
sb.append("John");
System.out.println(sb.length());















Q3: String class in Java is immutable.

What does the above statement mean?











Q4: Which of the following are valid string functions?



















Q5: Which of the following string initialization is correct?

1. String teststr = "test";
2. String teststr2 = new String ("test2");















Q6: What will be the output of the below code snippet?

String s1 = "Hello";
String s2 = "John";
System.out.println(s1.equals(s2));















Q7: What will be the output of the below code snippet?

String teststr = "testing";
char[] arr=teststr.toCharArray();
for(int p=arr.length-1;p>=0;p--) {
System.out.print(arr[p]);
}
















Q8: Select the correct output of the below code snippet:

String str = "Hi";
str.concat("John");
System.out.println(str.length());















Q9: Select the correct output of the below code snippet:

String[] strArr = {"hi","john","how","are", "you"};
System.out.println(strArr.length);















Q10: Which of the following methods is used to find the length of a String in Java?















Q11: Which of the following is not a valid string function in Java?















Q12: Which method removes whitespace from the beginning and end of a String in Java?















Q13: Select the correct output of the below code snippet:

String str7 = "orange";
String str8 = "orange";
System.out.println(str7 == str8);















Q14: Select the correct output of the below code snippet:

String str7 = "orange";
String str8 = new String("orange");
System.out.println(str7 == str8);


























More questions on Java String



Java string quiz