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

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. RIO-SEIO水泵流量表

    http://rio-seio.com/TW/products_pumps/Rio_plus.html 流量表:

  2. 将Web站点由IIS6迁移至IIS7

    最近开始着手逐步将所有的Web站点由Win2003+IIS6迁移至64位Win2008+IIS7,基本还算顺利.这里就把相关内容整理总结一下.首先自然是要安装基本运行环境,包括iis,.net fra ...

  3. autoit 将输入法修改为英文输入法

    如果能用ControlSend,就不推荐用send,如果非要用send,可以切换输入法为英文再send. $hWnd = WinGetHandle("[ACTIVE]");$hWn ...

  4. iconfont 图标字体

    iconfont 技术的主要是将图标转化为字体来减少应用体积.如需在项目中使用iconfont技术,图标矢量图一开始都应合并转化为字体库.   优点: 减小体积,字体文件比图片要小 图标保真缩放,解决 ...

  5. AX7: CREATE AN AUTOMATED TEST PACKAGE\MODEL

    AX7: CREATE AN AUTOMATED TEST PACKAGE\MODEL It’s really important for a stable solution the use of a ...

  6. 如何在IDEA上 添加GIT和maven、mybatis插件

    IDEA工具上,添加GIT和maven.mybatis插件,相对比较简单: 首先下载GIT.maven.mybatis. 先添加GIT插件: 首先在IDEA找到file中找到setting,然后搜索g ...

  7. GNS3 桥接虚拟网卡 telnet 实验

    网上很多桥接本地网卡的,一直测试不通.无奈,本人桥接vmware 虚拟网卡通! 1: 2: 3:telnet 加密实验 R1(config)#line vt R1(config)#line vty 0 ...

  8. MySQL 对于千万级的大表要怎么优化?

    作者:哈哈链接:https://www.zhihu.com/question/19719997/answer/81930332来源:知乎著作权归作者所有,转载请联系作者获得授权. 第一优化你的sql和 ...

  9. 26. linux查看端口占用情况

    linux系统下,查看端口占用情况的命令:lsof -i[root@www ~]# lsof -i

  10. lua学习笔记(一)

    lua是一种嵌入式的语言,首先安装. lua安装依赖于readline库,下载readline tar -zxvf readline-6.2.tar.gz cd readline-6.2 ./conf ...