package com;
public class GetStringEndAndStart {
public static void main(String[] args) {
// TODO Auto-generated method stub
String f1 ="hello.java";
System.out.println(f1);
boolean bool1 = f1.endsWith(".java");
boolean bool2 = f1.endsWith(".jpg");
System.out.println(bool1);
System.out.println(bool2);
System.out.println();
boolean bool3 =f1.startsWith("h");
boolean bool4 =f1.startsWith("hk");
boolean bool5 =f1.startsWith("hen");
System.out.println(bool3);
System.out.println(bool4);
System.out.println(bool5);
}
}
判断字符串首尾内容--startsWith与endsWith方法
最新推荐文章于 2023-11-08 20:34:30 发布
本文通过一个简单的Java程序示例介绍了如何使用Java内置方法来判断字符串是否以特定字符或子串开头及结尾。该示例代码展示了如何使用String类的startsWith和endsWith方法,并给出了具体的运行结果。
948

被折叠的 条评论
为什么被折叠?



