How To Check Whether A Given String Starts With A Specified Prefix Using The startsWith() Method

preview_player
Показать описание
How To Check Whether A Given String Starts With A Specified Prefix Using The startsWith() Method

In this video, we will talk about the startsWith() method, which is a method used for checking the prefix of a String. This method will return a Boolean value whenever it is evaluated. It returns true if the given String begins with the specified prefix or it will return false if the given String does not start with the specified prefix. Note that the specified prefix must be of type String too.

There are actually two ways to use this method

1. The first way is by using the method with a single parameter. Let me show you how by taking an example

String str = “Programming”;

If I run this program we will get : true
Because the String parameter is indeed the prefix of our given String variable str.

2. The second way to use this method is by passing two parameters that would represent the prefix and the starting index position

String str = “I love programming”;

Now I will call the method and pass the various parameters like this

The evaluation of this method will return true
Because, based on the parameters we have passed index position 2 will be considered as the starting point of the given String. We have passed the starting index position of 2, and when the method will search for the prefix love it will find out that this prefix begins exactly at index position 2

So guys, thanks for viewing, I hope this video has been informative and please don’t forget to support this channel by liking this video and by subscribing to this channel.

Let’s meet in another video

#codingriver
#java
#programming
Рекомендации по теме