Skip to content

An educational Java project explaining the String class and all its methods with example programs for learning and practice.

Notifications You must be signed in to change notification settings

Ankit0830/Java__String__Methods__Explained

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“Œ 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

  1. Length & Character Methods

    length() – Returns the total number of characters in the string

    charAt(int index) – Returns the character at a specific index

  2. Substring Methods

    substring(int beginIndex) – Returns substring from given index to end

    substring(int beginIndex, int endIndex) – Returns substring between indexes (endIndex - 1)

  3. 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.

  1. 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

  1. 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

  2. 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

About

An educational Java project explaining the String class and all its methods with example programs for learning and practice.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages