The indexof methods in java are: 1. [indexOf(String str)] returns the specified character str in the string; 2. [indexOf(String str, int index)] returns the specified character starting from the index position. str is the first index in the string.
The operating environment of this tutorial: windows7 system, java10 version, DELL G3 computer. This method is suitable for all brands of computers.
The indexof methods in java are:
1, indexOf(String str):
Returns the specified character str in the string (method caller ), or -1 if there is no such character in this string.
2, indexOf(String str, int index):
Returns the starting index of the first occurrence of the specified character str in the string starting from the index position. If this string If there is no such character, -1 is returned.
Example:
String str = "01234567890123456789"; System.out.println(str.indexOf("123")); System.out.println(str.indexOf("123",5));
The results of the above program are 1 and 11.
The indexOf() method in the first output function has only one parameter, so it returns the index of the first occurrence of 123 in str, which is 1; the indexOf() method in the first output function has Two parameters, the first parameter is the string 123 to be searched, and the second parameter is to start searching from the 5th position, so only the second 123 in str can be found, and the starting index of its occurrence is returned. , is 11.
Related free learning recommendations: java basic tutorial
The above is the detailed content of What are the indexof methods in java?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Linux new version
SublimeText3 Linux latest version

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software