首页 > 其他 > 详细

String类的常用判断方法使用练习

时间:2016-09-06 18:20:33      阅读:104      评论:0      收藏:0      [点我收藏+]

选取了一些常用的判断方法进行了使用练习,后续跟新其他方法

 

package StringDemo;
//   String类的判断方法解析
//   1:boolean equals();
//      判断字符串是否相等,区分大小写
//   2:boolean equalsIgnoreCase(String anotherString) 
//      将此 String 与另一个 String 比较,不考虑大小写
//   3.boolean contains(CharSequence s) 
//      判断字符串对象是否包含指定字符串

public class StringDemo {

    public static void main(String[] args) {
        String sc="helloworld";
        //1:boolean equals();
        //判断字符串是否相等,区分大小写
        System.out.println(sc.equals("HelloWorld"));
        System.out.println("-----------------------");
        
        // 2:boolean equalsIgnoreCase(String anotherString) 
        // 将此 String 与另一个 String 比较,不考虑大小写
        System.out.println(sc.equalsIgnoreCase("helloworld"));
        System.out.println("-----------------------");
        
        //3.boolean contains(CharSequence s) 
        //判断字符串对象是否包含指定字符串(需连续)
        System.out.println(sc.contains("hell"));
        System.out.println("-----------------------");
        
        // 4.boolean endsWith(String suffix) 
        //判断字符串是否以给定的字符结尾
        System.out.println(sc.endsWith("d"));
        System.out.println("-----------------------");
        
        //5.boolean startsWith (String prefix)
        //判断字符串是否以给定的字符串开头
        System.out.println(sc.startsWith("hell"));
        System.out.println("-----------------------");
        
        //6.boolean isEmpty();
        //判断字符串是否为空
        System.out.println(sc.isEmpty());
        System.out.println("-----------------------");
    }

}

 

String类的常用判断方法使用练习

原文:http://www.cnblogs.com/whj-1994/p/5846620.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!