Skip to main content

Strings — Part 2 MCQs with Explanations

Practice high-yield Programming & Software Development MCQs on Strings — Part 2 with worked academic solutions for FPSC, PPSC, NTS, NITB, PTS.

Questions
40
Difficulty Level
Exam-Level
Target Exams
FPSC, PPSC, NTS...
Estimated Time
48 mins
Exam-Level FPSC PPSC NTS NITB PTS
Verified for Commission Syllabus • Oct 14, 2026
40

Verified Practice Questions

Interactive test mode with detailed academic worked solutions

Live Progress | 0/40 answered
✓ 0 correct ✗ 0 wrong 0% score
Question 1 of 40
★ FPSC ★ PPSC

The String method compareTo() returns

Question 2 of 40
★ FPSC ★ PPSC

What is the output of the following println statement? String str1 = "Hellow"; System.out.println(str1.indexOf('t'));

Question 3 of 40
★ FPSC ★ PPSC

The class string belongs to ................. package.

Question 4 of 40
★ FPSC ★ PPSC

What will be the output? public class Test{ public static void main (String[] args){ String test = "a1b2c3"; String[] tokens = test.split("\\d"); for(String s: tokens) System.out.print(s); } }

Question 5 of 40
★ FPSC ★ PPSC

What will be the output of the following program code? public class Test{ public static void main(String args[]){ String s = "what"; StringBuffer sb = new StringBuffer("what"); System.out.print(sb.equals(s)+","+s.equals(sb)); } }

Question 6 of 40
★ FPSC ★ PPSC

What will be the output? public class Test{ public static void main(String args[]){ Object myObj = new String[]{"one", "two", "three"}; { for(String s : (String[])myObj) System.out.print(s + "."); } } }

Question 7 of 40
★ FPSC ★ PPSC

Determine output: public class Test{ public static void main(String args[]){ String str = null; if(str.length() == 0){ System.out.print("1"); } else if(str == null){ System.out.print("2"); } else{ System.out.print("3"); } } }

Question 8 of 40
★ FPSC ★ PPSC

Which of these methods is used to compare a specific region inside a string with another specific region in another string?

Question 9 of 40
★ FPSC ★ PPSC

What will be the output of the following Java code? class output { public static void main(String args[]) { StringBuffer s1 = new StringBuffer("Hello"); s1.insert(1,"Java"); System.out.println(s1); } }

Question 10 of 40
★ FPSC ★ PPSC

What will be the output of the following Java code? class output { public static void main(String args[]) { String c = "Hello i love java"; boolean var; var = c.startsWith("hello"); System.out.println(var); } }

Question 11 of 40
★ FPSC ★ PPSC

Which of these data type value is returned by equals() method of String class?

Question 12 of 40
★ FPSC ★ PPSC

Which of the following are incorrect form of StringBuffer class constructor?

Question 13 of 40
★ FPSC ★ PPSC

What will be the output of the following Java program? class output { public static void main(String args[]) { String c = " Hello World "; String s = c.trim(); System.out.println("\""+s+"\""); } }

Question 14 of 40
★ FPSC ★ PPSC

What will be the output of the following Java program? class output { public static void main(String args[]) { String a = "hello i love java"; System.out.println(a.indexOf('e')+" "+a.indexOf('a')+" "+a.lastIndexOf('l')+" "+a.lastIndexOf('v')); } }

Question 15 of 40
★ FPSC ★ PPSC

Which of these class is used to create an object whose character sequence is mutable?

Question 16 of 40
★ FPSC ★ PPSC

What will be the output of the following Java code? class output { public static void main(String args[]) { String s1 = "Hello i love java"; String s2 = new String(s1); System.out.println((s1 == s2) + " " + s1.equals(s2)); } }

Question 17 of 40
★ FPSC ★ PPSC

What will be the output of the following Java program? class output { public static void main(String args[]) { String s1 = "Hello"; String s2 = s1.replace('l','w'); System.out.println(s2); } }

Question 18 of 40
★ FPSC ★ PPSC

Which of these method of class String is used to remove leading and trailing whitespaces?

Question 19 of 40
★ FPSC ★ PPSC

What will be the output of the following Java code? class output { public static void main(String args[]) { StringBuffer sb=new StringBuffer("Hello"); sb.replace(1,3,"Java"); System.out.println(sb); } }

Question 20 of 40
★ FPSC ★ PPSC

In the following Java code, which code fragment should be inserted at line 3 so that the output will be: "123abc 123abc"? 1. StringBuilder sb1 = new StringBuilder("123"); 2. String s1 = "123"; 3. // insert code here 4. System.out.println(sb1 + " " + s1);

Question 21 of 40
★ FPSC ★ PPSC

Which of these methods of class String is used to check whether a given object starts with a particular string literal?

Question 22 of 40
★ FPSC ★ PPSC

Which of these method of class StringBuffer is used to find the length of current character sequence?

Question 23 of 40
★ FPSC ★ PPSC

What will be the output of the following Java code? class output { public static void main(String args[]) { String c = "Hello i love java"; int start = 2; int end = 9; char s[]=new char[end-start]; c.getChars(start,end,s,0); System.out.println(s); } }

Question 24 of 40
★ FPSC ★ PPSC

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

Question 25 of 40
★ FPSC ★ PPSC

Which of this method of class StringBuffer is used to reverse sequence of characters?

Question 26 of 40
★ FPSC ★ PPSC

What will s2 contain after following lines of Java code? StringBuffer s1 = "one"; StringBuffer s2 = s1.append("two")

Question 27 of 40
★ FPSC ★ PPSC

Which of this method of class StringBuffer is used to concatenate the string representation to the end of invoking string?

Question 28 of 40
★ FPSC ★ PPSC

What is the value returned by function compareTo() if the invoking string is greater than the string compared?

Question 29 of 40
★ FPSC ★ PPSC

What will be the output of the following Java program? class String_demo { public static void main(String args[]) { char chars[] = {'a', 'b', 'c'}; String s = new String(chars); System.out.println(s); } }

Question 30 of 40
★ FPSC ★ PPSC

Which of this method of class StringBuffer is used to get the length of the sequence of characters?

Question 31 of 40
★ FPSC ★ PPSC

What will be the output of the following Java program? class output { public static void main(String args[]) { String s1 = "one"; String s2 = s1 + " two"; System.out.println(s2); } }

Question 32 of 40
★ FPSC ★ PPSC

Which of this method of class String is used to extract a substring from a String object?

Question 33 of 40
★ FPSC ★ PPSC

What will be the output of the following Java program? class output { public static void main(String args[]) { String s1 = "Hello World"; String s2 = s1.substring(0 , 4); System.out.println(s2); } }

Question 34 of 40
★ FPSC ★ PPSC

What will be the output of the following Java code? class output { public static void main(String args[]) { char ch; ch = "hello".charAt(1); System.out.println(ch); } }

Question 35 of 40
★ FPSC ★ PPSC

What will be the output of the following Java program? class String_demo { public static void main(String args[]) { int ascii[] = { 65, 66, 67, 68}; String s = new String(ascii, 1, 3); System.out.println(s); } }

Question 36 of 40
★ FPSC ★ PPSC

What will be the output of the following Java program? class output { public static void main(String args[]) { String s = "Hello World"; int i = s.indexOf('o'); int j = s.lastIndexOf('l'); System.out.print(i + " " + j); } }

Question 37 of 40
★ FPSC ★ PPSC

What is the string contained in s after following lines of Java code? StringBuffer s new StringBuffer("Hello"); s.deleteCharAt(0);

Question 38 of 40
★ FPSC ★ PPSC

What will be the output of the following Java program? class output { class output { public static void main(String args[]) { char c[]={'A', '1', 'b' ,' ' ,'a' , '0'}; for (int i = 0; i < 5; ++i) { i++; if(Character.isDigit(c[i])) System.out.println(c[i]+" is a digit"); if(Character.isWhitespace(c[i])) System.out.println(c[i]+" is a Whitespace character"); if(Character.isUpperCase(c[i])) System.out.println(c[i]+" is an Upper case Letter"); if(Character.isLowerCase(c[i])) System.out.println(c[i]+" is a lower case Letter"); i++; } } }

Question 39 of 40
★ FPSC ★ PPSC

Which of this method of class String is used to obtain a length of String object?

Question 40 of 40
★ FPSC ★ PPSC

What will be the output of the following Java code? class output { public static void main(String args[]) { char c[]={'a', '1', 'b' ,' ' ,'A' , '0'}; for (int i = 0; i < 5; ++i) { if(Character.isDigit(c[i])) System.out.println(c[i]+" is a digit"); if(Character.isWhitespace(c[i])) System.out.println(c[i]+" is a Whitespace character"); if(Character.isUpperCase(c[i])) System.out.println(c[i]+" is an Upper case Letter"); if(Character.isLowerCase(c[i])) System.out.println(c[i]+" is a lower case Letter"); i=i+3; } } }

✓ Link copied to clipboard
Continue Your Practice

Advance Html — Part 1

Master the next curriculum module with 40 exam-standard MCQs.

Next Practice Set →

💡 Examiner's Advisory for Programming & Software Development

In competitive commission exams (FPSC, PPSC, KPPSC, SPSC, CSS, PMS), questions are frequently phrased with distractor options designed to catch rote learners. Whenever you answer an MCQ, read the Detailed Academic Explanation and Conceptual Anchor to understand why the remaining options are incorrect.

More Modules in Programming & Software Development

View All →
📚

Study Guides

Topic summaries and syllabus breakdown

Explore Guides →
🎯

Complete Library

Search through 78,000+ verified MCQs

Browse Library →
📱

Mobile App

Offline mock tests and instant bookmarks

Get Mobile App →