findsubstring.java

来自「JSF 演示代码」· Java 代码 · 共 17 行

JAVA
17
字号
/**
 * 查找特定的子串
 */
public class FindSubstring
{
	public static void main(String[] args)
	{
		String str = "welcome the boy.";
		System.out.println("Find the substring boy occurrence:" + str.indexOf("boy"));//查找子串
		System.out.println("Find the substring by occurrence:" + str.indexOf("by"));//查找子串
		System.out.println("Find the char t occurrence:" + str.indexOf('t'));//查找特定的字符	
		System.out.println("Test the string begin with wel.:" + str.startsWith("wel"));// 是否以"wel"开始
		System.out.println("Test the string end with boy.:" + str.endsWith("boy"));// 是否以"boy"结束

	}	
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?