π Project Name StringMethodPra
π Description
This project demonstrates the most commonly used methods of the Java String class.
The program explains how different String methods work with practical examples and output, making it very useful for Java beginners and students.
Java String is an immutable class, meaning once a String object is created, it cannot be changed. Any modification returns a new String object.
π Objectives
To understand Java String class methods
To learn how String manipulation works
To practice searching, comparison, and modification methods
To observe case-sensitive and case-insensitive behavior
π Topics Covered
-
Length & Character Methods
length() β Returns the total number of characters in the string
charAt(int index) β Returns the character at a specific index
-
Substring Methods
substring(int beginIndex) β Returns substring from given index to end
substring(int beginIndex, int endIndex) β Returns substring between indexes (endIndex - 1)
-
Modification Methods (Return New String)
toUpperCase() β Converts string to uppercase
toLowerCase() β Converts string to lowercase
trim() β Removes leading and trailing spaces
replace(char old, char new) β Replaces characters in string
Note: These methods do not modify the original string.
-
Checking Methods
startsWith(String prefix) β Checks if string starts with given value
endsWith(String suffix) β Checks if string ends with given value
β These methods are case-sensitive
-
Searching Methods
indexOf(String) β Finds first occurrence (Left to Right)
indexOf(String, fromIndex) β Starts search from specific index
lastIndexOf(String, fromIndex) β Searches from Right to Left
-
Comparison Methods
equals() β Compares content (case-sensitive)
equalsIgnoreCase() β Compares content ignoring case
== β Compares memory reference, not content
compareTo() β Lexicographical comparison (Dictionary order)
compareToIgnoreCase() β Comparison ignoring case
π compareTo() returns:
0 β Strings are equal
Positive value β First string is greater
Negative value β First string is smaller
π Key Learning Points
Java Strings are immutable
== should not be used for content comparison
equals() is preferred for value comparison
Case sensitivity affects many String methods
Every modification creates a new String object
π Technologies Used
Language: Java
IDE: NetBeans / Eclipse / IntelliJ
Package: stringmethodpra
π Suitable For
Java Beginners
BCA / MCA / B.Tech Students
College Assignments
Interview Preparation
GitHub Practice Projects
π Author
Ankit Sahu
Java Learner & Student