1. 程式人生 > >JavaSE8基礎 String startsWith 判斷A字符串是否以B字符串作為開頭

JavaSE8基礎 String startsWith 判斷A字符串是否以B字符串作為開頭

ips log ack with 源碼 cli gen start windows



os :windows7 x64
jdk:jdk-8u131-windows-x64
ide:Eclipse Oxygen Release (4.7.0)


code:

package jizuiku.t02;

public class Demo02 {
	public static void main(String[] args) {
		String s1 = "Hello World";
		String s2 = "hello";
		String s3 = "Hello";
		String s4 = "HellW";
		
		System.out.println(s1.startsWith(s2));
		System.out.println(s1.startsWith(s3));//"Hello World" 以 "Hello"作為開頭
		System.out.println(s2.startsWith(s1));
		System.out.println(s3.startsWith(s4));
	}
}


result:
技術分享


Java優秀,值得學習。
學習資源:API手冊+Java源碼。

JavaSE8基礎 String startsWith 判斷A字符串是否以B字符串作為開頭