
代码:
package cn.tedu.string;
public class StringDemo5 {
public static void main(String[] args) {
//字符串对象
String str1=“shf3hvsds”;
//判断新字符串是否是原串的子串
//子串—字符串中的内容包含而且连续
System.out.println(str1.contains(“shf3hv”));
//
String str=“xxxxx.avi”;
//判断原串是否以新串结尾
System.out.println(str.endsWith(“gv”));
//找电影后缀名
//文件类型 .txt .doc .ppt
System.out.println(str.endsWith(".avi"));
//判断原串是否以新串开始
//火车 G Z T
//车牌号 京 粤 鄂
System.out.println(str.startsWith("xx"));
}
}
输出:
true
false
true
true
代码图:

最后
以上就是曾经水杯最近收集整理的关于String类的contains()、endsWith()、startsWith()的全部内容,更多相关String类内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复