1. Which of the following correctly declares a String in Java?
a) String s = 'ICSE';
b) String s = "ICSE";
c) string s = "ICSE";
d) char s = "ICSE";
2. Strings in Java are:
a) Mutable reference types
b) Immutable reference types
c) Primitive data types
d) Mutable primitive types
3. What does length() of a String return?
a) Number of bytes
b) Index of last character
c) Number of characters
d) Number of words
4. Given String s = "BlueJ"; what is [Link](2)?
a) 'u'
b) 'e'
c) 'B'
d) 'l'
5. Which index is the first character stored at?
a) 0
b) 1
c) –1
d) Depends on JVM
6. Which statement creates an empty string?
a) String s = null;
b) String s = "";
c) String s = " ";
d) String s;
7. What is the difference between String and StringBuffer?
a) Both are mutable
b) Both are immutable
c) String is immutable, StringBuffer is mutable
d) String is mutable, StringBuffer is immutable
8. Output of [Link]("ICSE".length()); is:
a) 3
b) 4
c) 5
d) Compilation error
9. Which method gets a part of a string?
a) part()
b) piece()
c) substring()
d) segment()
10. What does "IcSe10".toUpperCase() return?
a) "IcSe10"
b) "ICSE10"
c) "icse10"
d) "IcSe10 "
11. A string literal in Java is enclosed in:
a) Single quotes
b) Double quotes
c) Backticks
d) Curly braces
12. Which is a valid string concatenation?
a) "Hello" + 10
b) "Hello" * 2
c) "Hello" / 2
d) "Hello" % 2
13. What is "JAVA" + 5 + 10?
a) JAVA510
b) JAVA15
c) JAVA15 (as string)
d) Compilation error
14. Strings are stored in:
a) Stack memory
b) Heap memory
c) ROM
d) Cache
15. A String pool in Java is used for:
a) Storing duplicate strings
b) Memory optimization
c) Thread safety
d) Sorting strings
16. Which method compares two strings ignoring case?
a) equals()
b) compareTo()
c) equalsIgnoreCase()
d) compareToIgnore()
17. For String a = "JAVA"; String b = "JAVA"; which is true?
a) a == b and [Link](b) both are true
b) Only [Link](b) can be true
c) Only a == b can be true
d) Both are always false
18. What is returned by [Link]('a') if character is not present?
a) 0
b) –1
c) 1
d) null
19. Which method checks if a string begins with a substring?
a) beginsWith()
b) startsWith()
c) starts()
d) prefix()
20. Given String s = "COMPUTER"; what is [Link]('T')?
a) 4
b) 5
c) 6
d) 7
21. Which correctly checks if s ends with "tion"?
a) [Link]("tion")
b) [Link]("tion")
c) [Link]("tion")
d) [Link]("tion")
22. What does lastIndexOf('A') return?
a) First occurrence
b) Last occurrence
c) Number of occurrences
d) Always –1
23. For String s = "banana"; [Link]("na") returns:
a) 1
b) 2
c) 3
d) 4
24. Which checks if two strings are exactly same (case-sensitive)?
a) s1 == s2
b) s1 = s2
c) [Link](s2)
d) [Link](s2)
25. Return type of compareTo() is:
a) boolean
b) int
c) char
d) String
26. "apple".compareTo("banana") returns:
a) Positive integer
b) Negative integer
c) 0
d) true
27. What does contains() method do?
a) Finds index of substring
b) Checks if substring exists
c) Counts occurrences
d) Removes substring
28. For String s = "ICSE"; [Link]("icse") returns:
a) true
b) false
c) Compilation error
d) 0
29. Which method returns true if both strings have same content (ignoring
case)?
a) equals()
b) equalsIgnoreCase()
c) compareTo()
d) contentEquals()
30. [Link](String str) returns:
a) First position of str
b) Last position of str
c) Length of str
d) Number of str occurrences
31. What does contains("xyz") return if substring not found?
a) true
b) false
c) –1
d) null
32. For case-sensitive comparison, use:
a) equals()
b) equalsIgnoreCase()
c) compareTo()
d) equals() and equalsIgnoreCase()
33. Which operator can be used to compare strings (with caution)?
a) ==
b) equals()
c) compareTo()
d) startsWith()
34. [Link](regex) is used for:
a) String comparison
b) Pattern matching
c) Substring search
d) Length comparison
35. "Hello".regionMatches(0, "Hello", 0, 5) returns:
a) true
b) false
c) 0
d) Compilation error
36. Output of "IcSe".toLowerCase() is:
a) "icse"
b) "IcSe"
c) "ICSE"
d) "icSe"
37. Which method removes leading and trailing spaces?
a) strip()
b) trim()
c) stripSpaces()
d) delete()
38. If s = " ICSE "; what is [Link]().length()?
a) 8
b) 6
c) 4
d) 2
39. To convert s to lowercase and store back:
a) [Link]();
b) toLowerCase(s);
c) s = [Link]();
d) [Link](s);
40. [Link]('a') returns:
a) 'A'
b) "A"
c) 'a'
d) "a"
41. Which method converts a single character to uppercase?
a) toUpper()
b) [Link]()
c) CharacterUpper()
d) upperChar()
42. " icse ".trim().toUpperCase() gives:
a) " icse "
b) " ICSE "
c) "ICSE"
d) "icse "
43. String s = ""; [Link]() returns:
a) true
b) false
c) 0
d) Compilation error
44. "HELLO".toLowerCase() followed by charAt(0) gives:
a) 'H'
b) 'h'
c) "h"
d) Compilation error
45. Which is not a valid String method?
a) replace()
b) substring()
c) reverse()
d) indexOf()
46. What does [Link]('a','e') do?
a) Deletes all 'a'
b) Replaces only first 'a' with 'e'
c) Replaces all 'a' with 'e'
d) Throws exception
47. "Hello".replaceAll("l", "L") returns:
a) "HeLlo"
b) "HeLLo"
c) "HeLlo"
d) "Hello"
48. "Apple".replaceFirst("p", "P") returns:
a) "APple"
b) "AppPle"
c) "APPle"
d) "Apple"
49. "ICSE10".toLowerCase() returns:
a) "ICSE10"
b) "icse10"
c) "IcSe10"
d) "icse10 "
50. To check if string contains only spaces:
a) isEmpty()
b) trim().isEmpty()
c) equals(" ")
d) Loop and check each character
51. For String s = "COMPUTER"; [Link](3) is:
a) "PUTER"
b) "PUTER "
c) "PUT"
d) "PUTE"
52. In substring(int begin, int end), characters are taken from:
a) begin to end (both inclusive)
b) begin+1 to end
c) begin inclusive, end exclusive
d) 0 to end
53. [Link](0, [Link]()) equals:
a) Empty string
b) Original string s
c) Last character
d) Compilation error
54. For String s = "ICSE"; which gives "CS"?
a) [Link](1,3)
b) [Link](2,4)
c) [Link](1,2)
d) [Link](0,2)
55. charAt() throws exception if index is out of range:
a) NullPointerException
b) StringIndexOutOfBoundsException
c) ArrayIndexOutOfBoundsException
d) NumberFormatException
56. Last valid index for string of length len:
a) len
b) len-1
c) len+1
d) 1
57. For String s = "HELLO"; [Link]([Link]()-1) is:
a) 'H'
b) 'E'
c) 'L'
d) 'O'
58. String s = "ABCD"; [Link](1,1) returns:
a) "A"
b) "B"
c) "" (empty string)
d) Throws exception
59. "HELLO".substring(1,4) returns:
a) "HELL"
b) "ELL"
c) "ELLO"
d) "ELLO"
60. Which converts other data types to String?
a) [Link]()
b) [Link]()
c) convert()
d) parseString()
61. For String s = "ICSE10"; which returns '1'?
a) [Link](5)
b) [Link](4)
c) Both a and b (different types)
d) [Link](4,5)
62. "Programming".substring(0,7) returns:
a) "Program"
b) "Programm"
c) "Program "
d) "Progra"
63. What does toCharArray() do?
a) Converts string to array of characters
b) Converts character to string
c) Stores characters in heap
d) Returns array index
64. String s = "Java"; [Link](1) returns:
a) 'J'
b) 'a'
c) 'v'
d) 'A'
65. "ABCDEF".substring(2) returns:
a) "AB"
b) "CDEF"
c) "ABCD"
d) "DEF"
66. Which method returns the first index of a character?
a) lastIndexOf()
b) indexOf()
c) firstIndexOf()
d) findIndex()
67. For string s = "Mississippi"; [Link]('i') returns:
a) 1
b) 4
c) 10
d) 11
68. getChars() method is used to:
a) Get all characters
b) Copy characters into array
c) Get character at index
d) Remove characters
69. "String".startsWith("Str") returns:
a) true
b) false
c) Throws exception
d) 0
70. [Link](0) on empty string throws:
a) NullPointerException
b) StringIndexOutOfBoundsException
c) Compilation error
d) Returns null
71. Which method checks if string is empty?
a) null
b) isEmpty()
c) isBlank()
d) equals("")
72. split() method is used to:
a) Join strings
b) Split string into array
c) Concatenate strings
d) Compare strings
73. "A,B,C".split(",") returns:
a) "A" "B" "C"
b) Array: ["A", "B", "C"]
c) String: "ABC"
d) Compilation error
74. To count vowels in a string, use:
a) for loop with charAt()
b) while(true)
c) do...while
d) indexOf()
75. To check if a string is a palindrome:
a) Sort characters
b) Compare with reverse
c) Count vowels
d) Use startsWith()
76. Which pair helps split a sentence into words?
a) length() and trim()
b) indexOf() and substring()
c) split() and loop
d) equals() and compareTo()
77. To convert "123" to integer 123:
a) [Link]("123")
b) [Link](123)
c) "123".toInteger()
d) [Link]("123")
78. Which counts spaces in string s?
a) [Link](' ')
b) Loop with if([Link](i) == ' ')
c) [Link](" ")++
d) [Link](' ','').length()
79. To remove all spaces from s:
a) s = [Link]();
b) s = [Link](" ","");
c) s = [Link](0);
d) s = [Link]();
80. To find number of words in sentence (space-separated):
a) [Link]() directly
b) Count spaces and add 1
c) [Link]() only
d) [Link]()
81. For alphabetical comparison of names:
a) [Link](b)
b) a == b
c) [Link](b)
d) [Link]() > [Link]()
82. [Link]() is used for:
a) Formatting output strings
b) Removing spaces
c) Converting to bytes
d) Replacing characters
83. What does trim() not remove?
a) Leading spaces
b) Trailing spaces
c) Internal spaces
d) Newline characters
84. " A B ".trim() returns:
a) "A B"
b) "A B"
c) " A B "
d) "AB"
85. To convert all lowercase to uppercase in loop:
a) Single toUpperCase() call
b) Loop through and use [Link]()
c) Use replaceAll()
d) Use replace()
86. StringBuffer vs String:
a) StringBuffer is faster for concatenation
b) String is faster for concatenation
c) Both are same
d) Depends on content
87. Which is thread-safe?
a) String
b) StringBuffer
c) StringBuilder
d) All three
88. [Link]() returns:
a) void
b) String
c) StringBuilder
d) int
89. To check if string matches pattern, use:
a) equals()
b) matches() with regex
c) compareTo()
d) indexOf()
90. "12345".matches("\\d+") returns:
a) true
b) false
c) Compilation error
d) null
91. Which method is used to find and replace using regex?
a) replace()
b) replaceAll() / replaceFirst()
c) substitute()
d) exchange()
92. [Link](123) returns:
a) 123 (int)
b) "123" (String)
c) Compilation error
d) null
93. To join array of strings with delimiter:
a) Loop and concatenate
b) [Link]()
c) StringBuffer
d) All of above
94. [Link]("-", "A", "B", "C") returns:
a) "ABC"
b) "A-B-C"
c) "A - B - C"
d) Compilation error
95. Which is immutable?
a) String
b) StringBuffer
c) StringBuilder
d) char[]
96. To reverse a string:
a) Use built-in reverse() (not in String)
b) Loop from end to start
c) Use [Link]()
d) Both b and c
97. StringBuffer sb = new StringBuffer("Hello"); [Link]()
gives:
a) "Hello"
b) "olleH"
c) "Hello "
d) Compilation error
98. Performance-wise, for large concatenations, prefer:
a) String concatenation with +
b) [Link]()
c) StringBuffer or StringBuilder
d) replaceAll()
99. Which method checks substring existence?
a) has()
b) contains()
c) includes()
d) isThere()
100. Which is best practice for ICSE board exam string programs?
a) Use only raw loops
b) Use built-in methods appropriately
c) Avoid String methods
d) Always use StringBuffer