zoukankan      html  css  js  c++  java
  • String字符串常见功能汇总

    构造方法摘要
    constructor
    String() 初始化一个新创建的 String 对象,使其表示一个空字符序列。
    String(byte[] bytes) 通过使用平台的默认字符集解码指定的 byte 数组,构造一个新的 String。
    String(byte[] bytes, int offset, int length) 通过使用平台的默认字符集解码指定的 byte 子数组,构造一个新的 String。
    String(char[] value) 分配一个新的 String,使其表示字符数组参数中当前包含的字符序列。
    String(char[] value, int offset, int count) 分配一个新的 String,它包含取自字符数组参数一个子数组的字符。


    method 方法
    char charAt(int index) 返回指定索引处的 char 值。

    int compareTo(String anotherString) 按字典顺序比较两个字符串。

    String concat(String str) 将指定字符串连接到此字符串的结尾

    boolean contains(CharSequence s) 当且仅当此字符串包含指定的 char 值序列时,返回 true。

    boolean endsWith(String suffix) 测试此字符串是否以指定的后缀结束。

    boolean equals(Object anObject) 将此字符串与指定的对象比较。

    boolean equalsIgnoreCase(String anotherString) 将此 String 与另一个 String 比较,不考虑大小写。

    byte[] getBytes() 使用平台的默认字符集将此 String 编码为 byte 序列,并将结果存储到一个新的 byte 数组中。

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

    int indexOf(int ch, int fromIndex) 返回在此字符串中第一次出现指定字符处的索引,从指定的索引开始搜索。

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

    boolean isEmpty() 当且仅当 length() 为 0 时返回 true。

    int length() 返回此字符串的长度

    boolean matches(String regex) 告知此字符串是否匹配给定的正则表达式。

    String replace(char oldChar, char newChar) 返回一个新的字符串,它是通过用 newChar 替换此字符串中出现的所有 oldChar 得到的。

    String replace(CharSequence target, CharSequence replacement) 使用指定的字面值替换序列替换此字符串所有匹配字面值目标序列的子字符串

    String replaceAll(String regex, String replacement) 使用给定的 replacement 替换此字符串所有匹配给定的正则表达式的子字符串。

    String[] split(String regex) 根据给定正则表达式的匹配拆分此字符串。

    boolean startsWith(String prefix) 测试此字符串是否以指定的前缀开始。

    String substring(int beginIndex) 返回一个新的字符串,它是此字符串的一个子字符串。

    String substring(int beginIndex, int endIndex) 返回一个新字符串,它是此字符串的一个子字符串。


    char[] toCharArray() 将此字符串转换为一个新的字符数组。

    String toLowerCase() 使用默认语言环境的规则将此 String 中的所有字符都转换为小写。

    String toUpperCase() 使用默认语言环境的规则将此 String 中的所有字符都转换为大写。


    String trim() 返回字符串的副本,忽略前导空白和尾部空白。

    String strip() Returns a string whose value is this string, with all leading and trailing white space removed.

    static String valueOf(int i) 返回 int 参数的字符串表示形式。

    static String valueOf(double d) 返回 double 参数的字符串表示形式。

  • 相关阅读:
    BeautifulSoup
    python爬虫操作excel
    requests
    urllib
    线程的基本用法
    WebView
    播放多媒体文件
    调用摄像头和相册
    03 pycharm编辑默认模板
    测试
  • 原文地址:https://www.cnblogs.com/haizinihao/p/14792807.html
Copyright © 2011-2022 走看看