Practice high-yield Programming & Software Development MCQs on Strings — Part 1 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
🎉 Set complete! All 40 questions answered.
Question 1 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following is true about Java strings?
Correct Answer: Option C — Strings can have a null value.
Detailed Academic Explanation:
Java strings are sequences of characters used to store and manipulate text data. Option A: Strings are mutable. → False. Java strings are immutable , meaning once a string is created, its value cannot be changed. If modifications are needed, a new string is created instead. Option B: Strings can contain only letters. → False. Java strings can contain letters, numbers, symbols, spaces, or any other character. For example, "Hello123!" and "Java@2024" are valid strings. Option C: Strings can have a null value. → True. A string variable can be assigned null, which means it does not reference any object in memory. Option D: Strings are implemented as arrays of characters. → True, but incomplete. Java internally represents strings as character arrays (char[]), but they are encapsulated in the String class, and we generally use methods rather than directly accessing the array. Thus, the correct answer is Option C: Strings can have a null value. .
💡Key Conceptual Anchor:Strings
Question 2 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the trim() method of a String object in Java?
Correct Answer: Option D — To remove leading and trailing whitespace
Detailed Academic Explanation:
The trim() method in Java is used to remove whitespace characters from the beginning and end of a string. It does not remove spaces or whitespace characters that are in the middle of the string. For example: String s = " Hello World "; System.out.println(s.trim()); // Output: "Hello World" Therefore, the correct purpose of the trim() method is to remove leading and trailing whitespace only, not all spaces, not concatenation, and not substring extraction.
💡Key Conceptual Anchor:Strings
Question 3 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following methods is used to replace all occurrences of a specified character in a string in Java?
Correct Answer: Option A — replace()
Detailed Academic Explanation:
replace() is a method in Java used to replace all occurrences of a specified character or substring in a string with another character or substring. It takes two parameters: the character or substring to be replaced and the new character or substring. replaceAll() is used for replacing all substrings that match a regular expression, which is different from replace() . replaceChar() and replaceAllOccurrences() are not valid methods in Java.
💡Key Conceptual Anchor:Strings
Question 4 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
The output of the following fraction of code is public class Test{ public static void main(String args[]){ String s1 = new String("Hello"); String s2 = new String("Hellow"); System.out.println(s1 = s2); } }
Correct Answer: Option B — Hellow
Detailed Academic Explanation:
The output of the given code will be: In the code, two String objects s1 and s2 are created with the values "Hello" and "Hellow" (note the typo in "Hellow"), respectively. Then, the System.out.println() statement prints the result of the assignment s1 = s2 . This assignment sets the value of s1 to the same value as s2 , which is "Hellow". As a result, the println statement prints the value of s1 , which is "Hellow".
💡Key Conceptual Anchor:Strings
Question 5 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Determine output: public class Test{ public static void main(String args[]){ String s1 = "SITHA"; String s2 = "RAMA"; System.out.println(s1.charAt(0) > s2.charAt(0)); } }
Correct Answer: Option A — true
Detailed Academic Explanation:
Output will be True. Since when s1.charAt(0) ascii value is greater then s2.charAt(0). So it will return True.
💡Key Conceptual Anchor:Strings
Question 6 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output? String str1 = "abcde"; System.out.println(str1.substring(1, 3));
Correct Answer: Option B — bc
Detailed Academic Explanation:
substring() method has two variants and returns a new string that is a substring of this string. The substring begins with the character at the specified index and extends to the end of this string or upto endIndex - 1 if second argument is given. Syntax: Here is the syntax of this method: public String substring( int beginIndex ) or public String substring( int beginIndex , int endIndex ) Parameters: Here is the detail of parameters: beginIndex -- the begin index, inclusive. endIndex -- the end index, exclus
💡Key Conceptual Anchor:Strings
Question 7 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following program? public class Test{ public static void main(String args[]){ String str1 = "one"; String str2 = "two"; System.out.println(str1.concat(str2)); } }
Correct Answer: Option C — onetwo
Detailed Academic Explanation:
Concat() method appends one String to the end of another. The method returns a String with the value of the String passed into the method appended to the end of the String which is used to invoke this method.
💡Key Conceptual Anchor:Strings
Question 8 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
String str1 = "Kolkata".replace('k', 'a'); In the above statement, the effect on string Kolkata is
Correct Answer: Option B — All characters k are replaced by a.
Detailed Academic Explanation:
replace() method returns a new string resulting from replacing all occurrences of oldChar in this string with newChar. Syntax: Here is the syntax of this method: public String replace( char oldChar , char newChar ) Parameters: Here is the detail of the parameters: oldChar -- the old character. newChar -- the new character. Return Value: It returns a string derived from this string by replacing every occurrence of oldChar with newChar.
💡Key Conceptual Anchor:Strings
Question 9 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How many objects will be created? String a = new String("Examveda"); String b = new String("Examveda"); String c = "Examveda"; String d = "Examveda";
Correct Answer: Option B — 3
Detailed Academic Explanation:
Object will be created each time whenever we use new keyword. So, 2 object will be created simply for the first two line and matter is with remaining two bottom line. String c="examveda" creates an object and store it in String pool, next time when we are writing String d="examveda" it will first check in String pool whether object already exists or not. Since, it is existing, no new object will be created. Hence reference "d" points to existing object "examveda". So ultimately 3 object will be created at the end.
💡Key Conceptual Anchor:Strings
Question 10 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How many Constructor String class have?
Correct Answer: Option C — 13
Detailed Academic Explanation:
The String class has over 60 methods and 13 constructors. Source : oracle.com
💡Key Conceptual Anchor:Strings
Question 11 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be output? String S1 = "S1 ="+ "123"+"456"; String S2 = "S2 ="+(123+456);
Correct Answer: Option A — S1=123456, S2=579
Detailed Academic Explanation:
If a number is quoted in "" then it becomes a string, not a number any more.
💡Key Conceptual Anchor:Strings
Question 12 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In Java, which class is used to represent a sequence of characters as a string?
Correct Answer: Option A — String
Detailed Academic Explanation:
String is the correct answer to “In Java, which class is used to represent a sequence of characters as a string”. This question is standard in competitive examination syllabi for Strings.
💡Key Conceptual Anchor:Strings
Question 13 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the correct way to create a new empty String object in Java?
Correct Answer: Option E — Both A and B
Detailed Academic Explanation:
Both A and B is the correct answer to “What is the correct way to create a new empty String object in Java”. This question is standard in competitive examination syllabi for Strings.
💡Key Conceptual Anchor:Strings
Question 14 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In Java, which operator is used to concatenate two strings?
Correct Answer: Option A — +
Detailed Academic Explanation:
+ is the correct answer to “In Java, which operator is used to concatenate two strings”. This question is standard in competitive examination syllabi for Strings.
💡Key Conceptual Anchor:Strings
Question 15 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following methods is used to compare two strings for equality in Java?
Correct Answer: Option A — equals()
Detailed Academic Explanation:
equals() is the correct answer to “Which of the following methods is used to compare two strings for equality in Java”. This question is standard in competitive examination syllabi for Strings.
💡Key Conceptual Anchor:Strings
Question 16 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What does the length() method of a String object in Java return?
Correct Answer: Option C — The length of the string
Detailed Academic Explanation:
The length of the string is the correct answer to “What does the length() method of a String object in Java return”. This question is standard in competitive examination syllabi for Strings.
💡Key Conceptual Anchor:Strings
Question 17 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How do you convert a string to lowercase in Java?
Correct Answer: Option B — str.toLowerCase()
Detailed Academic Explanation:
str.toLowerCase() is the correct answer to “How do you convert a string to lowercase in Java”. This question is standard in competitive examination syllabi for Strings.
💡Key Conceptual Anchor:Strings
Question 18 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the charAt() method of a String object in Java?
Correct Answer: Option C — To get the character at a specific index
Detailed Academic Explanation:
To get the character at a specific index is the correct answer to “What is the purpose of the charAt() method of a String object in Java”. This question is standard in competitive examination syllabi for Strings.
💡Key Conceptual Anchor:Strings
Question 19 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which method is used to find the index of the first occurrence of a specified character in a string in Java?
Correct Answer: Option B — indexOf()
Detailed Academic Explanation:
indexOf() is the correct answer to “Which method is used to find the index of the first occurrence of a specified character in a string in Java”. This question is standard in competitive examination syllabi for Strings.
💡Key Conceptual Anchor:Strings
Question 20 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In Java, what is the result of the expression "Hello".substring(1, 4)?
Correct Answer: Option C — "ell"
Detailed Academic Explanation:
"ell" is the correct answer to “In Java, what is the result of the expression "Hello".substring(1, 4)”. This question is standard in competitive examination syllabi for Strings.
💡Key Conceptual Anchor:Strings
Question 21 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the correct way to check if a string starts with a specific prefix in Java?
Correct Answer: Option A — str.startsWith(prefix)
Detailed Academic Explanation:
str.startsWith(prefix) is the correct answer to “What is the correct way to check if a string starts with a specific prefix in Java”. This question is standard in competitive examination syllabi for Strings.
💡Key Conceptual Anchor:Strings
Question 22 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which method is used to split a string into an array of substrings based on a specified delimiter in Java?
Correct Answer: Option A — split()
Detailed Academic Explanation:
split() is the correct answer to “Which method is used to split a string into an array of substrings based on a specified delimiter in Java”. This question is standard in competitive examination syllabi for Strings.
💡Key Conceptual Anchor:Strings
Question 23 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In Java, what is the purpose of the endsWith() method of a String object?
Correct Answer: Option A — To check if the string ends with a specified character
Detailed Academic Explanation:
To check if the string ends with a specified character is the correct answer to “In Java, what is the purpose of the endsWith() method of a String object”. This question is standard in competitive examination syllabi for Strings.
💡Key Conceptual Anchor:Strings
Question 24 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What method is used to convert an integer to a string in Java?
Correct Answer: Option A — String.valueOf()
Detailed Academic Explanation:
String.valueOf() is the correct answer to “What method is used to convert an integer to a string in Java”. This question is standard in competitive examination syllabi for Strings.
💡Key Conceptual Anchor:Strings
Question 25 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following is the correct way to compare two strings in a case-insensitive manner in Java?
Correct Answer: Option C — str1.equalsIgnoreCase(str2)
Detailed Academic Explanation:
str1.equalsIgnoreCase(str2) is the correct answer to “Which of the following is the correct way to compare two strings in a case-insensitive manner in Java”. This question is standard in competitive examination syllabi for Strings.
💡Key Conceptual Anchor:Strings
Question 26 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In Java, what does the concat() method of a String object do?
Correct Answer: Option A — Combines two strings.
Detailed Academic Explanation:
Combines two strings. is the correct answer to “In Java, what does the concat() method of a String object do”. This question is standard in competitive examination syllabi for Strings.
💡Key Conceptual Anchor:Strings
Question 27 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How do you find the last index of a specified character in a string in Java?
Correct Answer: Option A — str.lastIndexOf(char)
Detailed Academic Explanation:
str.lastIndexOf(char) is the correct answer to “How do you find the last index of a specified character in a string in Java”. This question is standard in competitive examination syllabi for Strings.
💡Key Conceptual Anchor:Strings
Question 28 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the result of the expression "Java".replace("a", "o") in Java?
Correct Answer: Option A — "Jovo"
Detailed Academic Explanation:
"Jovo" is the correct answer to “What is the result of the expression "Java".replace("a", "o") in Java”. This question is standard in competitive examination syllabi for Strings.
💡Key Conceptual Anchor:Strings
Question 29 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following is true about string concatenation in Java?
Correct Answer: Option D — It doesn't change the original strings.
Detailed Academic Explanation:
It doesn't change the original strings. is the correct answer to “Which of the following is true about string concatenation in Java”. This question is standard in competitive examination syllabi for Strings.
💡Key Conceptual Anchor:Strings
Question 30 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How do you find the index of the last occurrence of a substring in a string in Java?
Correct Answer: Option B — str.lastIndexOf(substring)
Detailed Academic Explanation:
str.lastIndexOf(substring) is the correct answer to “How do you find the index of the last occurrence of a substring in a string in Java”. This question is standard in competitive examination syllabi for Strings.
💡Key Conceptual Anchor:Strings
Question 31 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the toLowerCase() method of a String object in Java?
Correct Answer: Option B — To convert the string to lowercase.
Detailed Academic Explanation:
To convert the string to lowercase. is the correct answer to “What is the purpose of the toLowerCase() method of a String object in Java”. This question is standard in competitive examination syllabi for Strings.
💡Key Conceptual Anchor:Strings
Question 32 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which method is used to extract a substring from a string in Java?
Correct Answer: Option C — substring()
Detailed Academic Explanation:
substring() is the correct answer to “Which method is used to extract a substring from a string in Java”. This question is standard in competitive examination syllabi for Strings.
💡Key Conceptual Anchor:Strings
Question 33 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In Java, what is the purpose of the isEmpty() method of a String object?
Correct Answer: Option A — To check if the string is empty.
Detailed Academic Explanation:
To check if the string is empty. is the correct answer to “In Java, what is the purpose of the isEmpty() method of a String object”. This question is standard in competitive examination syllabi for Strings.
💡Key Conceptual Anchor:Strings
Question 34 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How do you check if a string contains a specific character in Java?
Correct Answer: Option A — str.contains(char)
Detailed Academic Explanation:
str.contains(char) is the correct answer to “How do you check if a string contains a specific character in Java”. This question is standard in competitive examination syllabi for Strings.
💡Key Conceptual Anchor:Strings
Question 35 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the substring() method of a String object in Java?
Correct Answer: Option B — To extract a substring from the string
Detailed Academic Explanation:
To extract a substring from the string is the correct answer to “What is the purpose of the substring() method of a String object in Java”. This question is standard in competitive examination syllabi for Strings.
💡Key Conceptual Anchor:Strings
Question 36 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How do you find the first index of a specified character in a string in Java?
Correct Answer: Option D — str.indexOf(char)
Detailed Academic Explanation:
str.indexOf(char) is the correct answer to “How do you find the first index of a specified character in a string in Java”. This question is standard in competitive examination syllabi for Strings.
💡Key Conceptual Anchor:Strings
Question 37 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following program code? class LogicalCompare{ public static void main(String args[]){ String str1 = new String("OKAY"); String str2 = new String(str1); System.out.println(str1 == str2); } }
Correct Answer: Option B — false
Detailed Academic Explanation:
false is the correct answer to “What will be the output of the following program code? class LogicalCompare{ public static void main(String args[]){ String str1 = new String("OKAY"); String str2 = new String(str1); System.out.println(str1 == str2); } }”. This question is standard in competitive examination syllabi for Strings.
💡Key Conceptual Anchor:Strings
Question 38 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following program? public class Test{ public static void main(String args[]){ String s1 = "java"; String s2 = "java"; System.out.println(s1.equals(s2)); System.out.println(s1 == s2); } }
Correct Answer: Option D — true true
Detailed Academic Explanation:
true true is the correct answer to “What will be the output of the following program? public class Test{ public static void main(String args[]){ String s1 = "java"; String s2 = "java"; System.out.println(s1.equals(s2)); System.out.println(s1 == s2); } }”. This question is standard in competitive examination syllabi for Strings.
💡Key Conceptual Anchor:Strings
Question 39 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What could be output of the following fragment of code? public class Test{ public static void main(String args[]){ String x = "hellow"; int y = 9; System.out.println(x += y); } }
Correct Answer: Option B — hellow9
Detailed Academic Explanation:
hellow9 is the correct answer to “What could be output of the following fragment of code? public class Test{ public static void main(String args[]){ String x = "hellow"; int y = 9; System.out.println(x += y); } }”. This question is standard in competitive examination syllabi for Strings.
💡Key Conceptual Anchor:Strings
Question 40 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
toString() method is defined in
Correct Answer: Option B — java.lang.Object
Detailed Academic Explanation:
java.lang.Object is the correct answer to “toString() method is defined in”. This question is standard in competitive examination syllabi for Strings.
💡Key Conceptual Anchor:Strings
✓Link copied to clipboard
Continue Your Practice
Advance Html — Part 1
Master the next curriculum module with 40 exam-standard MCQs.
💡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.