Get the App
SLTechnology News&Howtos  ›  Servers  › 

How does Java return the specified string subscript

Shulou Source: shulou.com Published: 2022-06-01 14:22:23 09月28日 Update

This article mainly explains "how Java returns the specified string subscript". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how Java returns the specified string subscript"!

Use the indexOf or lastIndexOf method in Java to obtain the subscript for the first occurrence of a specified character in a string.

1.indexOf

Public int indexOf (String str, int fromIndex) looks for the first occurrence of the subscript of String str in a string. Starting with int fromIndex, the return value is an integer.

String str = "wanag"; str.indexOf ("a"); / / returns 1

2.lastIndexOf

Public int lastIndexOf (String str, int fromIndex) reverse lookup.

String str = "wanag"; str.lastIndexOf ("a"); / / return 3 so far. I believe you have a better understanding of "how Java returns the specified string subscript". You might as well do it in practice! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Characters subscript string content method first time learning practical deeper interest practical practical easy to operate more friends websites channels query Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info OPPO Reno macOS NVidia MariaDB