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

ICSE Class 10 Java String Notes

This document provides an overview of Java Strings, defining them as immutable sequences of characters and detailing their creation methods, including string literals and the new keyword. It outlines commonly used string methods such as length(), charAt(), and equals(), and clarifies the difference between equals() and == for string comparison. Key points for ICSE exams are also highlighted, emphasizing the immutability of strings and the starting index of 0.
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)
7 views2 pages

ICSE Class 10 Java String Notes

This document provides an overview of Java Strings, defining them as immutable sequences of characters and detailing their creation methods, including string literals and the new keyword. It outlines commonly used string methods such as length(), charAt(), and equals(), and clarifies the difference between equals() and == for string comparison. Key points for ICSE exams are also highlighted, emphasizing the immutability of strings and the starting index of 0.
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 – Java String Notes

1. What is a String?
A String is a sequence of characters. In Java, String is a class present in the [Link]
package. Strings are objects, not primitive data types.
Example:
String name = "ICSE";

2. Creating Strings
(a) Using String literal
String s1 = "Computer";

• Stored in String Constant Pool.


• If the same value already exists, memory is reused.
(b) Using new keyword
String s2 = new String("Computer");

• Creates a new object in heap memory.

3. Characteristics of String
• Strings are immutable (cannot be changed).

• Any modification creates a new String object.


Example:
String s = "Java";
s = s + " ICSE";

4. Commonly Used String Methods


• length() – returns number of characters

• charAt(index) – returns character at given index (index starts from 0)

• toUpperCase() – converts string to uppercase

• toLowerCase() – converts string to lowercase

• equals() – compares content of two strings

• compareTo() – compares strings lexicographically

• substring() – extracts part of a string

• indexOf() – returns index of a character or substring

5. equals() vs ==
equals() compares the content of strings.
== compares the reference (memory address).
Example:
String a = "ICSE";
String b = new String("ICSE");
[Link](b) // true
a == b // false

6. Important Points for ICSE Exams


• Index of string starts from 0.

• String is immutable.

• Use equals() to compare strings.

• String class is in [Link] package (no import required).

You might also like