java 字符串 字符查找_java之字符串中查找字串的常见方法

1、int indexOf(String str) :返回第一次出现的指定子字符串在此字符串中的索引。

int indexOf(String str, int startIndex):从指定的索引处开始,返回第一次出现的指定子字符串在此字符串中的索引。

函数数名:indexOf

调用方式:Object(String).indexOf(String str,int startIndex)或String.indexOf(String str)

参数说明:str需要查找的字串.

startIndex 从指定的索引处开始查询,if (startIndex<0),则在程序执行中认为startIndex=0;

if(startIndex>Object.length) 则它被当作最大的可能索引。then 正常查询。

返回内容:if (在Object中查找到字串)返回字串第一次出现的索引

if(在Object中没有查找到字串) return -1

返回值类型:int

example:

/**

*

Title:LookSubstring

*

This program demostrate "look for a substring from known String"

*

Filename:LookSubstring.java

* @ author 14941

* @ version 1.0

*/

public class LookSubstring

{

public

你可能感兴趣的:(java,字符串,字符查找)