Thanks to visit codestin.com
Credit goes to www.scribd.com

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

GR 10 String Handling Notes

The document provides an overview of various Java String methods, including their descriptions, syntax, and examples. It covers methods for manipulating strings, such as length, charAt, indexOf, substring, and case conversion. Additionally, it introduces the concept of strings in Java, highlighting their immutability and ways to create them.

Uploaded by

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

GR 10 String Handling Notes

The document provides an overview of various Java String methods, including their descriptions, syntax, and examples. It covers methods for manipulating strings, such as length, charAt, indexOf, substring, and case conversion. Additionally, it introduces the concept of strings in Java, highlighting their immutability and ways to create them.

Uploaded by

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

Method Description Syntax Example

Returns number of
length() characters in the str.length() "Hello".length() → 5
string.

Returns character at
charAt(int index) the given index (0- str.charAt(1) "Java".charAt(2) → 'v'
based).

Finds first index of


indexOf(char ch) str.indexOf('a') "banana".indexOf('a')
given character.

Finds index of
indexOf(char ch, int "banana".indexOf('a', 2
character from given str.indexOf('a', 2)
startIndex) 3
index.

Finds last occurrence str.lastIndexOf('a' "banana".lastIndexOf('


lastIndexOf(char ch)
index of character. ) 5

Extracts substring
substring(int "Welcome".substring(3
from start index to str.substring(3)
startIndex) "come"
end.

substring(int start, int Extracts substring "Welcome".substring(1


str.substring(1, 4)
end) from start to (end - 1). "elc"

Converts all letters to "ICSE".toLowerCase() →


toLowerCase() str.toLowerCase()
lowercase. "icse"

Converts all letters to "java".toUpperCase() →


toUpperCase() str.toUpperCase()
uppercase. "JAVA"

Replaces all old


replace(char old, char "banana".replace('a','e
characters with new str.replace('a','e')
new) "benene"
ones.

replace(CharSequence Replaces all old


str.replace("is", "This is".replace("is", "
oldSeq, CharSequence substrings with new
"was") → "Thwas was"
newSeq) ones.

Joins the given string str.concat(" "Hello".concat(" World


concat(String s)
to the end. World") "Hello World"

Checks if two strings


"Java".equals("java") →
equals(String s) are exactly the same str.equals("Java")
false
(case-sensitive).
Method Description Syntax Example

equalsIgnoreCase(Stri Checks string equality str.equalsIgnoreC "Java".equalsIgnoreCa


ng s) ignoring case. ase("java") va") → true

Lexicographically str.compareTo("a "banana".compareTo("


compareTo(String s)
compares strings. pple") ") → 1

Lexicographic
compareToIgnoreCase( str.compareToIgn "apple".compareToIgno
compare ignoring
String s) oreCase("Apple") se("Apple") → 0
case.

Removes spaces from


trim() str.trim() " Java ".trim() → "Java"
start and end.

Checks if string ends str.endsWith("en "weekend".endsWith("


endsWith(String suffix)
with the given suffix. d") → true

String.valueOf(primitiv Converts primitive to String.valueOf(12


String.valueOf(123) →
e) string. 3)

parseXxx(String s) e.g. Converts string to Integer.parseInt(" Integer.parseInt("456"


Integer.parseInt(s) primitive type. 456") 456

✅ 1. Introduction to Strings

 A String in Java is a sequence of characters.

 Strings are objects of the String class in java.lang package.

 They are immutable: Once created, their values cannot be


changed.

✅ 2. Declaring and Creating Strings

Ways to create strings:

1. String literal

String name = "ICSE";

2. Using new keyword

String name = new String("ICSE");

📘 Java String Methods – With Description, Syntax, Example &


Explanation

You might also like