0% found this document useful (0 votes)
8 views2 pages

ICSE Class 10 String Handling Guide

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

ICSE Class 10 String Handling Guide

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

ICSE Class 10 - String Handling (Chapter 4)

Fill in the Blanks


• concat() method is used to join two strings.
• The output of the following statement, when executed:
[Link]("COMPUTER".charAt(4));
• The output of the statement, when executed: [Link]("Object Oriented".length());
• ___ operator is used to concatenate two strings.
• String declaration is terminated by the symbol ___.
• Character literal is enclosed within ___.
• The return type of the statement equals() is ___.
• The output of "VIDYALAYA.".substring(2,5) will result in ___.

Write down the syntax to perform the following tasks


• To check whether a character (chr) is in upper case or not.
• To compare two Strings (str1, str2) are same or not.
• To extract the last character of a word (wd) stored in the variable chr.
• To return the first occurrence of 'a' in the word "applications".
• To replace the word "old" with the word "new" in a given String st = "old is always old".
• To check if the second character of a String (str) is in upper case.

Predict the output of the following statements


• [Link]("ABCDEF".compareTo("ABcDEF"));
• [Link]("CYBER".equals("cyber"));
• [Link]("computer".toUpperCase());
• [Link]("India".substring(1,4));
• [Link]("Welcome".charAt(3));
• [Link]("Object".replace('t','s'));
• [Link]("Examination".lastIndexOf('i'));
• [Link]("STREAM".indexOf('R'));

Differentiate between the following functions


• equals() and compareTo()
• indexOf() and lastIndexOf()
• toLowerCase() and toUpperCase()
• length() and charAt()

Short Answer Questions


• Name the function that: (i) returns the character at a particular index, (ii) returns the index of first
occurrence of a character, (iii) removes blank spaces from the beginning and end of a string, (iv)
returns a new string replacing old characters with new ones.
• How many objects and reference variables are created in the following statement? String s1 =
new String("Java");
• Differentiate between immutable and mutable objects with examples.
• What will be the output of the following code: String s1 = "Examination"; String s2 = "Examination";
String s3 = new String("Examination"); [Link](s1==s2); [Link](s1==s3);

Describe the purpose of the following functions with syntax and


example
• concat()
• compareTo()
• substring()
• equalsIgnoreCase()
• indexOf()

Programs (Unsolved Questions)


• Write a program to input a word and display the new word formed by shifting each character to the
next alphabet. Example: INPUT: COMPUTER → OUTPUT: DPONQVFS
• Write a program to input a sentence and print each word of the sentence in separate lines.
• Write a program to input a word and check whether it is palindrome or not.
• Write a program to input a sentence and display the number of words present in it.
• Write a program to input a word and display the word in alphabetical order.

Common questions

Powered by AI

In the statement `String s1 = new String("Java");`, one string object and one reference variable are created. The new String("Java") expression explicitly creates a new string object, separate from the 'Java' string literal that might already exist in the string pool. The reference variable `s1` is then assigned to the new string object created in the heap memory, making one distinct object from the pool and the heap .

The method substring(2,5) extracts a portion of the string starting at index 2 and ending at index 5, but not including the character at index 5. For the string "VIDYALAYA.", the extraction begins at the third character 'D' (index 2) and includes up to, but not including, the sixth character. Thus, the output will be "DYA" . The substring method selects characters from the starting index until the index preceding the end index.

The concat() method is preferred in cases where only two strings are being concatenated because it directly joins them without the overhead that the '+' operator introduces. The '+' operator is more versatile as it can concatenate multiple strings more conveniently in a single expression, but this flexibility comes at the cost of creating additional temporary string objects, which can be less efficient in large-scale operations . Therefore, concat() is preferred when optimizing performance for a minimal number of string concatenations.

String immutability in Java means that once a string is created, it cannot be altered. This has several implications on performance and memory use. Immutability ensures thread safety when strings are used concurrently without explicit synchronization . Moreover, constant strings can be shared within the string pool, reducing memory footprint by reusing instances of identical strings. However, when modifications are frequent, as each change results in the creation of a new string object, memory usage can increase, causing potential performance overhead in applications that involve numerous string manipulations .

The charAt() method returns the character at a specified position in a string, where the index is zero-based, meaning the first character has an index of 0 . In contrast, the length() method returns the total number of characters in a string, which includes spaces and special characters . While charAt() requires an index parameter to return a single character, length() does not; it simply provides an overall numeric value representing the string's length.

The method toLowerCase() converts all the characters in a string to lower case, whereas toUpperCase() converts all the characters to upper case . The key difference is the final casing of the letters, with toLowerCase() ensuring no uppercase letters remain, and toUpperCase() removing any lowercase letters by converting them all to uppercase.

The equals() method is used to compare two strings for equality, returning a boolean value (true if the strings are identical, and false otherwise). In contrast, the compareTo() method returns an integer indicating the lexical comparison of the two strings: 0 if they are identical, a positive number if the caller string is lexically greater, and a negative number if it is lexically less . Thus, while equals() provides a simple equality check, compareTo() offers a more detailed comparison with relative ordering information.

The expression `System.out.println("ABCDEF".compareTo("ABcDEF"));` will result in a positive number because the compareTo() method performs a lexicographical comparison character by character based on Unicode values. In Unicode, uppercase letters have smaller numeric values than lowercase letters. Hence, when comparing the third character 'C' from "ABCDEF" and 'c' from "ABcDEF", the comparison yields a positive value as 'C' is lexicographically less than 'c' . This result illustrates the case sensitivity of the compareTo() method.

You might also like