On this page
The ICSE Computer Applications syllabus asks for String handling twice over: outputs of String methods, and full programs that work on strings. The good news is that most programs repeat a handful of patterns. This post lists what the syllabus covers, gives five patterns with code we compiled and ran, and goes through the output traps that catch careful students.
Which String methods does the ICSE syllabus list?
The ICSE 2027 Computer Applications syllabus puts String handling in Class X. It names these methods: trim, toLowerCase, toUpperCase, length, charAt, indexOf, lastIndexOf, concat, equals, equalsIgnoreCase, compareTo, compareToIgnoreCase, replace, substring (both forms), startsWith, endsWith and valueOf. It asks for programs on "extracting and modifying characters of a string", alphabetical order of strings in an array using bubble and selection sort, and linear search for a string. The suggested assignments add palindrome strings, pig Latin and alphabetical order of characters. The ICSE 2028 syllabus, released in January 2026, keeps the same method list.
What do the key methods return?
The official Java String documentation settles most doubts:
Strings are immutable: "their values cannot be changed after they are created". Methods like replace and toUpperCase return a new string.
substring(begin, end) "extends to the character at index endIndex - 1", so the end index is excluded and the length is end − begin.
indexOf returns −1 "if the character does not occur".
compareTo returns the difference of the first pair of different characters, this.charAt(k) − other.charAt(k), or, if one string is a prefix of the other, the difference of the lengths.
Pattern 1: visit every character
Almost every program starts with this loop. Counting vowels:
String s = "Computer Applications";
int vowels = 0;
for (int i = 0; i < s.length(); i++) {
char ch = Character.toLowerCase(s.charAt(i));
if ("aeiou".indexOf(ch) != -1) vowels++;
}
System.out.println(vowels); // 8The indexOf trick replaces five comparisons. Character.toLowerCase is in the syllabus's library-class list, and lowering first means capital A is counted.
Pattern 2: build a new string, then compare
Strings cannot be changed in place, so you build a new one. A palindrome check:
String w = "Malayalam", rev = "";
for (int i = w.length() - 1; i >= 0; i--)
rev = rev + w.charAt(i);
System.out.println(rev.equalsIgnoreCase(w) ? "Palindrome" : "Not a palindrome");This prints Palindrome. With equals instead of equalsIgnoreCase it would print Not a palindrome, because of the capital M.
Pattern 3: find a position, then cut
Pig Latin moves the letters before the first vowel to the end and adds "AY":
String word = "TROUBLE";
int k = 0;
while (k < word.length() && "AEIOU".indexOf(word.charAt(k)) == -1) k++;
System.out.println(word.substring(k) + word.substring(0, k) + "AY"); // OUBLETRAYThe condition k < word.length() comes first so the loop stops safely on a word with no vowels.
Pattern 4: look at neighbours
To capitalise the first letter of each word, check whether the previous character is a space. Adding a space at the front lets one loop handle the first word too: start the loop at index 1 of " " + sentence and upper-case any character whose left neighbour is a space.
Pattern 5: sort an array of strings
Bubble sort works on strings exactly as on numbers, with compareTo in place of >:
String[] names = {"Rohan", "anita", "Kabir", "Diya"};
for (int i = 0; i < names.length - 1; i++)
for (int j = 0; j < names.length - 1 - i; j++)
if (names[j].compareToIgnoreCase(names[j + 1]) > 0) {
String t = names[j]; names[j] = names[j + 1]; names[j + 1] = t;
}This gives anita, Diya, Kabir, Rohan. With plain compareTo, "anita" would sort last, because lower-case letters have higher codes than capitals.
Output traps to practise
We ran each of these in Java 21:
"apple".compareTo("apricot") is −2 ('p' minus 'r').
"Apple".compareTo("apple") is −32 ('A' is 65, 'a' is 97).
"app".compareTo("apple") is −2, the difference in lengths.
"KOLKATA".substring(2, 5) is "LKA": indices 2, 3 and 4.
"India".indexOf('i') is 3, because the capital I at index 0 does not match.
"India".charAt(2) + "India".indexOf('i') prints 103, not d3: a char plus an int is arithmetic, and 'd' is 100.
new String("ICSE") == "ICSE" is false, while equals gives true.
Common mistakes and how to avoid them
Looping to i <= length(), which throws an exception at the last step.
Calling s.replace('a', 'o') and printing s, which is unchanged; print the returned string.
Using == for comparison, or compareTo when case should not matter.
Forgetting that substring's second index is excluded.
A practice routine for strings
Each day for a week, write one program from the five patterns without notes, run it, and then predict the output of five method calls before running them. Keep a list of every output you got wrong and why. Our guide to ICSE Computer Applications covers the rest of the paper.
When a program runs but gives the wrong output and you cannot see why, the Fermi Problem Library has worked problems with a step-by-step solver that explains the reasoning rather than printing an answer.
Start now: predict what "Fermi".compareTo("Fermat") returns, then run it to check.



