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

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类的常用判断方法使用练习的更多相关文章

  1. String类中常用的方法

    @Test public void demo(){ // 以下为String中的常用的方法及注释, 最常用的注释前有**标注 String s = "abcdefg123456"; ...

  2. 27 string类中常用的方法列表

    1. 获取方法 int length()     获取字符串的长度 char charAt(int index) 获取特定位置的字符 (角标越界) int indexOf(String str) 获取 ...

  3. String类中常用的方法(重要)

    1.字符串与字节 public String(byte[] byte); 将全部字节变成字符串 public String (byte[] byte,int offset,int length) 将部 ...

  4. Java中String类中常用的方法

    1.字符串与字符数组的转换 用toCharArray()方法将字符串变为字符数组 String str = "abcdef"; char c[] = str.tocharArray ...

  5. String 类的常用字符串方法

    public class Page106 { /** * 字符串练习第五章 * @param args */ public static void main(String[] args) { Stri ...

  6. 2017.12.11 String 类中常用的方法

    1.编写程序将 "jdk" 全部变为大写,并输出到屏幕,截取子串"DK" 并输出到屏幕 package demo; import java.util.Scann ...

  7. js中关于string的一些常用的方法

    最近总结了一些关于string中的常用方法, 其中大部分的方法来自于<JavaScript框架设计>这本书, 如果有更好的方法,或者有关于string的别的常用的方法,希望大家不吝赐教. ...

  8. String类中的equals()方法:

    String类中的equals()方法: public boolean equals(Object anObject) { //如果是同一个对象 if (this == anObject) { ret ...

  9. Java用代码演示String类中的以下方法的用法

    用代码演示String类中的以下方法的用法 (1)boolean isEmpty(): 判断字符串是不是空串,如果是空的就返回true (2)char charAt(int index): 返回索引上 ...

随机推荐

  1. 我的 Kernel

    求真 工作之后,渐渐与人打交道,人情世俗也慢慢接触了,领了工资之后,也可以买一些自己喜欢的东西,感觉也开始像一个独立完整的人了. 所见所闻也有所想了,有些理念开始慢慢转变了.但是,不知道为什么,对于假 ...

  2. 使用delphi+intraweb进行微信开发5—准备实现微信API,先从获取AccessToken开始

    在前4讲中我们已经使iw开发的应用成功和微信进行了对接,再接下来的章节中我们开始逐一尝试和实现微信的各个API,开始前先来点准备工作 首先需要明确的是,微信的API都是通过https调用实现的,分为p ...

  3. XXX esx.problem.syslog.nonpersistent.formatOnHost not found XXX

    ESXi 主机的摘要选项卡报告以下错误:配置问题:XXX esx.problem.syslog.nonpersistent.formatOnHost 未找到 XXX (2101811)   Sympt ...

  4. 网络编程(一):用C#下载网络文件的2种方法

    使用C#下载一个Internet上的文件主要是依靠HttpWebRequest/HttpWebResonse和WebClient.具体处理起来还有同步和异步两种方式,所以我们其实有四种组合. 1.使用 ...

  5. Visual Studio 2012 trial version

    Update: vs2012.5.iso http://download.microsoft.com/download/9/F/1/9F1DEA0F-97CC-4CC4-9B4D-0DB45B8261 ...

  6. pthread 学习

    1. 创建线程 int pthread_create (pthread_t* thread, pthread_attr_t* attr, void* (*start_routine)(void*), ...

  7. ASP.NET权限管理

    ASP.NET Web Forms权限管理: 我要将一个文件夹只能让一个用户组访问怎么办? 可否在网站根目录下的web.config里这样设置: <location path="adm ...

  8. gulp使用笔记

    gulp简介 gulp 是基于 Nodejs 的自动任务运行器,能自动化地完成javascript/coffee/sass/less/html/image/css等文件的的测试.检查.合并.压缩.格式 ...

  9. RBAC在thinkphp中有Auth类 可以很好的实现权限控制

    import('ORG.Util.Auth');//加载类库 $auth=new Auth(); if($auth->check('show_button',1)){// 第一个参数是规则名称, ...

  10. vs2008注册组件

    开始—运行 输入 regsvr32+路径