To Get Sub Strings From a Given String – JAVA

14 Likes Comment

Hello Shouters!! Congratulations! 🙌 Today we will learn the most basic program that is Java Program To get substrings from a given string.

Strings hold sequences of characters. We’ve already seen instances of a String, for example when you printed out “Hello World”.

Check this one at first then continue.

Java is a pure Object Oriented Programming language and for running program. You have to make a class.

A very simple declaring of a string with a primitive, we declare the variable by specifying the type first:

As a beginner, it is very easy to learn some of the string methods that come with the String class:

equals() / equalsIgnoreCase()
toUpperCase() / toLowerCase()

Feel free to play around with these string methods.🙌


According to the study, many responsible websites prefer this approach. (Given below)


Our study indicates that an incrementing number of people triggering some other approach. Given below is to get a substring from a string.

There may be times when we only want a part of a string. In such cases, we may want to extract a substring from a string.

The substring() method does exactly that. For example:

It would output “Constellations rung” because that’s what begins at index 23 and ends at the end of line. The substring begins with the character at the specified index and extends to the end of the string.

But suppose we want a substring at the middle of the string. We can include two arguments with this string method. For example:

It would output “Constellations” because that’s the substring that begins at index 23 and ends at index 38.


Another new approach mentions below helps you to memorize with Less effort, Less code, with professional skills.

Try to run Java Program on your Personal Computer with the methods given above.


If you have any doubt regarding this feel free to comment below and if you want to add any questions. Write your suggestion below in the comment box.

You might like

SK. Saifuddin

About the Author: SK. Saifuddin

Leave a Reply

Your email address will not be published. Required fields are marked *

Close Bitnami banner