zoukankan      html  css  js  c++  java
  • String类的常用判断方法使用练习

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

    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("-----------------------");
        }
    
    }
  • 相关阅读:
    电商需求与表结构设计参考
    使用EF操作Oracle数据库小计
    jenkins构建随笔
    NET平台开源项目速览(6)FluentValidation验证组件介绍与入门(转载)
    api接口签名相关文章
    C# 如何防止重放攻击(转载)
    .NET 4中的多线程编程之一:使用Task(转载)
    Flash 无法输入中文的修正方法
    Nape的回调系统 nape.callbacks
    Nape刚体body.align();
  • 原文地址:https://www.cnblogs.com/whj-1994/p/5846620.html
Copyright © 2011-2022 走看看