java如何在字符串中查找
- 编程技术
- 2025-02-08 04:47:21
- 1
![java如何在字符串中查找](http://xinin56.com/imgs/108.jpg)
在Java中,你可以使用几种不同的方法来在字符串中查找子字符串。以下是一些常见的方法: 使用 `indexOf` 方法`indexOf` 方法返回子字符串在字符串中第一...
在Java中,你可以使用几种不同的方法来在字符串中查找子字符串。以下是一些常见的方法:
使用 `indexOf` 方法
`indexOf` 方法返回子字符串在字符串中第一次出现的位置。如果没有找到子字符串,则返回 `-1`。
```java
public class Main {
public static void main(String[] args) {
String str = "Hello, World!";
String substr = "World";
int index = str.indexOf(substr);
System.out.println("Index of '" + substr + "': " + index);
本文由夕逆IT于2025-02-08发表在夕逆IT,如有疑问,请联系我们。
本文链接:http://www.xinin56.com/bian/512775.html
本文链接:http://www.xinin56.com/bian/512775.html
上一篇:江西科技学校是几本大学
下一篇:河南大学是985还是211合集