Based on the use of string indexof () in Java

There are four methods (indexof ()) to find substrings of strings in Java

The indexof method returns an integer value indicating the starting position of the substring in the string object. If no substring is found, - 1 is returned.

If StartIndex is negative, StartIndex is treated as zero. If it is larger than the largest character position index, it is regarded as the largest possible index.

There are four methods to find substrings of strings in Java, as follows:

1. Int indexof (string STR): returns the index of the specified substring in this string for the first time.

2. Int indexof (string STR, int StartIndex): starting from the specified index, returns the index of the specified substring in this string for the first time.

3. Int lastIndexOf (string STR): returns the index of the specified substring appearing on the rightmost side of this string.

4. Int lastIndexOf (string STR, int StartIndex): search backward from the specified index and return the index of the specified substring that last appears in this string.

Although it's simple, I'll take a note.

The running results of the above code are as follows:

The above article on the use of string indexof () based on Java is all that Xiaobian has shared with you. I hope it can give you a reference and support more programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>