Java字符串——startWith endWith

startWith()、endWith()

分别用于是否以指定的内容开始或结束。返回都是布尔类型。

例子如下:

——————————

String str1="my java is poor";
  String str2="my android is rookies too";
  boolean isMy1 = str1.startsWith("my");
  boolean isMy2 = str1.startsWith("java", 2);
  boolean isMy3 = str2.endsWith("too");
  System.out.println("isMy1 = "+isMy1+"\n"+"isMy2 = "+isMy2+"\n"+"isMy3 = "+isMy3);

运行结果如下:

isMy1 = true
isMy2 = false
isMy3 = true

——————————

String str1="my java is poor";
  String str2="my android is rookies too";
  boolean isMy1 = str1.startsWith("my");
  boolean isMy2 = str1.startsWith("java", 3);
  boolean isMy3 = str2.endsWith("too");
  System.out.println("isMy1 = "+isMy1+"\n"+"isMy2 = "+isMy2+"\n"+"isMy3 = "+isMy3);

运行结果如下:

isMy1 = true
isMy2 = true
isMy3 = true





你可能感兴趣的:(java)