⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 indexofdemo.java

📁 JAVA编程思想源代码 值得一下 很难找的
💻 JAVA
字号:
package chapter8;

public class IndexOfDemo {

	public static void main(String[] args) {
		String s1 = "AbCdEAbCdE";
		String s2 = "Ab";
		System.out.println("s1:" + s1 + "     s2:" + s2);
		System.out.println("从头向后查找。。。。。。");
		if (s1.indexOf(s2) != -1) {
			System.out.println("s2是s1的子串");
			System.out.println("s2在s1中的位置为:" + s1.indexOf(s2));
		} else {
			System.out.println("s2不是s1的子串");
		}
		System.out.println("从第二个字符开始向后查找。。。。。。");
		if (s1.indexOf(s2, 1) != -1) {
			System.out.println("s2是s1的子串");
			System.out.println("s2在s1中的位置为:" + s1.indexOf(s2, 1));
		} else {
			System.out.println("s2不是s1的子串");
		}
		System.out.println("从字符串末尾开始向前查找。。。。。。");
		if (s1.lastIndexOf(s2) != -1) {
			System.out.println("s2是s1的子串");
			System.out.println("s2在s1中的位置为:" + s1.lastIndexOf(s2));
		} else {
			System.out.println("s2不是s1的子串");
		}
		System.out.println("从字符串末尾第三个字符开始向前查找。。。。。。");
		if (s1.lastIndexOf(s2, 2) != -1) {
			System.out.println("s2是s1的子串");
			System.out.println("s2在s1中的位置为:" + s1.lastIndexOf(s2, 2));
		} else {
			System.out.println("s2不是s1的子串");
		}

	}

}

⌨️ 快捷键说明

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