zoukankan      html  css  js  c++  java
  • String中具有的方法

    String是在Java.lang包下的,具有多种方法:计算字符串长度,比较字符串,连接字符串,提取字符串等
        1、确定字符串的长度:使用length()方法
        2、比较字符串:提供equals()方法 比较的是存储在两个字符串对象的内容是否相同(只在字符串中)
                        "=="与equals的区别:"=="比较的是地址,equals比较的是内容
                    忽略大小写比较:使用equalsIgnoreCase()方法     toLowerCase()变成小写   toUpperCase()变成大写
        3、连接字符串: (1)使用"+"   
                       (2)concat()方法  eg:String s = "你好,";String name = "张三";String ss = s.concat(name);
        4、提取字符串:常用的提取方法: indexOf(int ch)、indexOf(String value) 搜索第一个出现的位置(或字符串value)
            lastIndexOf(int ch)、lastIndexOf(String value)搜索最后一个出现的位置(或字符串value)
            substring(beginIndex,endIndex+1)方法 提取从beginIndex到endIndex+1位置的字符串
            String[] s = phone.split(String s)方法将一个字符串分割成子字符串

  • 相关阅读:
    android 自定义dialog 易扩展
    android 圆角item shape
    模板方法模式
    观察者模式
    工厂方法模式(选自《设计模式之禅》)
    单例模式
    如何快速创建静态WEB站点
    React Native 插件系列之lottie-react-native
    JavaJavaScript小问题系列之JSON解析
    React Native 插件系列之PushNotificationIOS
  • 原文地址:https://www.cnblogs.com/lxxia-blog/p/4457777.html
Copyright © 2011-2022 走看看