zoukankan      html  css  js  c++  java
  • String类的判断功能

    public boolean equals(Object obj): 比较字符串的内容是否相同,区分大小写

    public boolean equalsIgnoreCase(String str): 比较字符串的内容是否相同,忽略大小写

    public boolean contains(String str): 判断字符串中是否包含传递进来的字符串

    public boolean startsWith(String str): 判断字符串是否以传递进来的字符串开头

    public boolean endsWith(String str): 判断字符串是否以传递进来的字符串结尾

    public boolean isEmpty(): 判断字符串的内容是否为空

    public int length(): 获取字符串的长度。

    public char charAt(int index): 获取指定索引位置的字符

    public int indexOf(int ch): 返回指定字符在此字符串中第一次出现处的索引。

    public int indexOf(String str): 返回指定字符串在此字符串中第一次出现处的索引。

    public int indexOf(int ch,int fromIndex):返回指定字符在此字符串中从指定位置后第一次出现处的索引。

    public int indexOf(String str,int fromIndex): 返回指定字符串在此字符串中从指定位置后第一次出现处的索引。public String substring(int start): 从指定位置开始截取字符串,默认到末尾。

    public String substring(int start,int end): 从指定位置开始到指定位置结束截取字符串。

    public byte[] getBytes(): 把字符串转换为字节数组。

    public char[] toCharArray(): 把字符串转换为字符数组。

    public static String valueOf(char[] chs): 把字符数组转成字符串。

    public static String valueOf(int i): 把int类型的数据转成字符串。

    注意:String类的valueOf方法可以把任意类型的数据转成字符串。

    public String toLowerCase(): 把字符串转成小写。

    public String toUpperCase(): 把字符串转成大写。

    public String concat(String str): 把字符串拼接。

    public String replace(char old,char new) 将指定字符进行互换

    public String replace(String old,String new) 将指定字符串进行互换

    public String trim() 去除两端空格

    String的按字典顺序比较两个字符串及案例演示

    public int compareTo(String str) 会对照ASCII 码表 从第一个字母进行减法运算 返回的就是这个减法的结果

    如果前面几个字母一样会根据两个字符串的长度进行减法运算返回的就是这个减法的结果

    如果连个字符串一摸一样 返回的就是0

    public int compareToIgnoreCase(String str) 跟上面一样 只是忽略大小写的比较

    欢迎大家批评指正,指出问题,谢谢!

  • 相关阅读:
    ps入门之photoshop文件操作-打开与存储认识 (PS界面介绍)如何新建文档(03)
    ps入门之ps的工作界面的认识学习(界面介绍)界面的组成(02)
    markdown编辑器Typora
    5FAE8F6F96C59ED1字体
    清除浮动float (:after方法)
    SQL中Truncate的用法
    复合索引
    RESTful API 设计指南
    两种js方法发起微信支付:WeixinJSBridge,wx.chooseWXPay区别
    nuxt.js 简述
  • 原文地址:https://www.cnblogs.com/yhcTACK/p/15391206.html
Copyright © 2011-2022 走看看