startswith 和 endswith 输出的结果为布尔值( Boolean ),是输出true,否则输出false。
开始位置判断 ( startswith )
startswith(String S):判断字符串开始位置是否为子串S。
startswith(String S, int start):判断字符串从下标start开始是否为子串S。
endswith(String S):判断字符串结束位置是否为子串S。
import java.math.*; import java.util.*; public class Main { public static void main(String[] args) { // TODO Auto-generated method stub String S = "0123456789"; System.out.println(S.endsWith("789"));//输出true 判断字符串结尾是否为子串"789",是输出true否输出false System.out.println(S.startsWith("012"));//输出true 判断字符串开始是否为子串"789",是输出true否输出false System.out.println(S.startsWith("012", 1));//输出false 判断字符串从下标位置1开始是否为子串"012",是输出true否输出false } }