STRING HANDLING
Concepts & Advanced Question Bank
ICSE Class 10 • Computer Applications • Chapter 8
Refined notes · board-style hard questions · full worked Java solutions
Built for board, pre-board, unit test and last-minute revision
,Table of Contents
PART 1 — CONCEPT NOTES 3
1.1 Three Ways to Handle Character Data . . . . . . . . . . . . . . . . . . . . . . . . .3
1.2 Creating String Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.3 The Immutability Rule . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.4 Creating StringBuffer Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.5 String vs StringBuffer — The Comparison Board Loves . . . . . . . . . . . . . . . . . 4
1.6 String Class Methods — Full Reference . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.7 StringBuffer Methods & Chaining . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.8 length() vs capacity() — The Efficiency Story . . . . . . . . . . . . . . . . . . . . . . 7
1.9 Six Traps Every Topper Falls For . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
PART 2 — QUESTION BANK 9
2.1 Section A — Objective Type (Hard) . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.2 Section A2 — Short Answer Theory (2 Marks Each) . . . . . . . . . . . . . . . . . . 11
2.3 Section B — Output-Based / Program Tracing (Hard) . . . . . . . . . . . . . . . . . 13
2.4 Section C — Programming Questions (Complex & Board-Style) . . . . . . . . . . . . 16
PART 3 — RAPID REVISION 33
3.1 One-Page Method Cheat Sheet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
3.2 Common Mistakes — Quick List . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
3.3 Last-Minute Formula Box . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
,String Handling — Concepts & Question Bank ICSE Class 10 • Computer Applications
PART 1 — CONCEPT NOTES
A tight, exam-focused pass through Chapter 8 before you get to the question bank. Every trap that shows up
in Part 2 is flagged here first.
▌ 1.1 Three Ways to Handle Character Data
Java gives you three tools for character data, and board papers expect you to know which one
fits which job:
– char / Character — a single character (Character is the wrapper class around char).
– String — a sequence of characters that is immutable (cannot be changed after creation).
– StringBuffer — a sequence of characters that is mutable (can be edited in place).
● ADDITIONAL INFO
Both String and StringBuffer live in java.lang, which is imported automatically — you never
need an explicit import statement for either one.
▌ 1.2 Creating String Objects
There are two ways to create a String:
String name = "I am a student"; // (i) string literal
String copy = new String("Hello"); // (ii) using the new operator
String empty = new String(); // an empty string
Three features you can be asked to state directly: a String stores characters accessible by index,
it offers methods for concatenation/comparison/searching, and — most importantly — it is
immutable.
▌ 1.3 The Immutability Rule
A classic board trap: this code compiles and runs with no error, even though String is immutable.
String city = "Delhi";
city = "Mumbai"; // no error!
Java does not edit the "Delhi" object. It quietly builds a brand-new String object holding "Mumbai"
and re-points the reference variable city to it. The old "Delhi" object still exists in memory, just
unreachable.
1
, String Handling — Concepts & Question Bank ICSE Class 10 • Computer Applications
Fig. 1 — Immutability: a new object is created, the reference simply moves.
★ MUST REMEMBER
"Immutable" means the object’s content never changes — it says nothing about whether the
variable can be reassigned to point elsewhere.
▌ 1.4 Creating StringBuffer Objects
StringBuffer objects are always built with new — there is no literal shorthand. Three constructors
are examinable:
StringBuffer sb1 = new StringBuffer(); // empty, default capacity 16
StringBuffer sb2 = new StringBuffer("First"); // holds "First", capacity = 5 + 16 = 21
StringBuffer sb3 = new StringBuffer(15); // empty, capacity fixed at 15
Constructor What it does
new StringBuffer() Empty buffer, default capacity of 16 characters.
new StringBuffer("txt") Buffer pre-loaded with "txt"; capacity = length("txt") + 16.
new StringBuffer(n) Empty buffer with capacity fixed at n — avoids repeated reallocation if you
already know roughly how big the content will get.
▌ 1.5 String vs StringBuffer — The Comparison Board
Loves
2
Concepts & Advanced Question Bank
ICSE Class 10 • Computer Applications • Chapter 8
Refined notes · board-style hard questions · full worked Java solutions
Built for board, pre-board, unit test and last-minute revision
,Table of Contents
PART 1 — CONCEPT NOTES 3
1.1 Three Ways to Handle Character Data . . . . . . . . . . . . . . . . . . . . . . . . .3
1.2 Creating String Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.3 The Immutability Rule . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.4 Creating StringBuffer Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.5 String vs StringBuffer — The Comparison Board Loves . . . . . . . . . . . . . . . . . 4
1.6 String Class Methods — Full Reference . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.7 StringBuffer Methods & Chaining . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.8 length() vs capacity() — The Efficiency Story . . . . . . . . . . . . . . . . . . . . . . 7
1.9 Six Traps Every Topper Falls For . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
PART 2 — QUESTION BANK 9
2.1 Section A — Objective Type (Hard) . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.2 Section A2 — Short Answer Theory (2 Marks Each) . . . . . . . . . . . . . . . . . . 11
2.3 Section B — Output-Based / Program Tracing (Hard) . . . . . . . . . . . . . . . . . 13
2.4 Section C — Programming Questions (Complex & Board-Style) . . . . . . . . . . . . 16
PART 3 — RAPID REVISION 33
3.1 One-Page Method Cheat Sheet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
3.2 Common Mistakes — Quick List . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
3.3 Last-Minute Formula Box . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
,String Handling — Concepts & Question Bank ICSE Class 10 • Computer Applications
PART 1 — CONCEPT NOTES
A tight, exam-focused pass through Chapter 8 before you get to the question bank. Every trap that shows up
in Part 2 is flagged here first.
▌ 1.1 Three Ways to Handle Character Data
Java gives you three tools for character data, and board papers expect you to know which one
fits which job:
– char / Character — a single character (Character is the wrapper class around char).
– String — a sequence of characters that is immutable (cannot be changed after creation).
– StringBuffer — a sequence of characters that is mutable (can be edited in place).
● ADDITIONAL INFO
Both String and StringBuffer live in java.lang, which is imported automatically — you never
need an explicit import statement for either one.
▌ 1.2 Creating String Objects
There are two ways to create a String:
String name = "I am a student"; // (i) string literal
String copy = new String("Hello"); // (ii) using the new operator
String empty = new String(); // an empty string
Three features you can be asked to state directly: a String stores characters accessible by index,
it offers methods for concatenation/comparison/searching, and — most importantly — it is
immutable.
▌ 1.3 The Immutability Rule
A classic board trap: this code compiles and runs with no error, even though String is immutable.
String city = "Delhi";
city = "Mumbai"; // no error!
Java does not edit the "Delhi" object. It quietly builds a brand-new String object holding "Mumbai"
and re-points the reference variable city to it. The old "Delhi" object still exists in memory, just
unreachable.
1
, String Handling — Concepts & Question Bank ICSE Class 10 • Computer Applications
Fig. 1 — Immutability: a new object is created, the reference simply moves.
★ MUST REMEMBER
"Immutable" means the object’s content never changes — it says nothing about whether the
variable can be reassigned to point elsewhere.
▌ 1.4 Creating StringBuffer Objects
StringBuffer objects are always built with new — there is no literal shorthand. Three constructors
are examinable:
StringBuffer sb1 = new StringBuffer(); // empty, default capacity 16
StringBuffer sb2 = new StringBuffer("First"); // holds "First", capacity = 5 + 16 = 21
StringBuffer sb3 = new StringBuffer(15); // empty, capacity fixed at 15
Constructor What it does
new StringBuffer() Empty buffer, default capacity of 16 characters.
new StringBuffer("txt") Buffer pre-loaded with "txt"; capacity = length("txt") + 16.
new StringBuffer(n) Empty buffer with capacity fixed at n — avoids repeated reallocation if you
already know roughly how big the content will get.
▌ 1.5 String vs StringBuffer — The Comparison Board
Loves
2