我是靠谱客的博主 曾经水杯,这篇文章主要介绍String类的contains()、endsWith()、startsWith(),现在分享给大家,希望可以做个参考。

在这里插入图片描述
代码:
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类内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(132)

评论列表共有 0 条评论

立即
投稿
返回
顶部