• java String的各种方法及操作


    No.

    方法名称

    功能

    字符与字符串

    01

    public String(char[] value)

    将字符数组中所有内容变为字符串

    02

    public String(char[] value,int offset,int count)

    将字符数组中部分内容变为字符串

    03

    public char charAt(int index)

    取得指定索引位置的字符,索引从0开始

    04

    public char[] toCharArray()

    将字符串变为字符数组返回

    字节与字符串

    01

    public String(byte[] bytes)

    将字节数组中所有内容变为字符串

    02

    public String(byte[] bytes,int offset,int length)

    将字节数组中部分内容变为字符串

    03

    public byte[] getBytes()

    将字符串以字节数组的形式返回

    04

    public byte[] getBytes(String charsetName) throws UnsupportedEncodingExcepetion

    编码转换处理

    字符串比较

    01

    public boolean equals(String anObject)

    区分大小写比较

    02

    public boolean equalsIgnoreCase(String anotherString)

    不区分大小写比较

    03

    public int compareTo(String anotherString)

    比较两个字符串的大小关系

    字符串查找

    01

    public boolean contains(String s)

    判断一个子字符串是否存在(JDK1.5以后才有)

    02

    public int indexOf(String str)

    从头开始查找指定字符的位置,查到了返回位置的开始索引,查不到返回-1(JDK1.5以后推荐使用contains)

    03

    public int indexOf(String str,int fromIndex)

    从指定位置查找子字符的位置

    04

    public int lastIndex(String str)

    从后往前查找子字符的位置

    05

    public int lastIndex(String str,int fromIndex)

    从指定位置由后往前查找子字符的位置

    06

    public boolean startsWith(String prefix)

    从头开始判断是否以指定的字符串开头

    07

    public boolean startsWith(String prefix,int toffset)

    从指定位置开始判断是否以指定的字符串开头

    08

    public boolean endsWith(String suffix)

    判断是否以指定的字符串结尾

    字符串替换

    01

    public String replaceAll(String regex,String replacement)

    替换所有内容

    02

    public String replaceFirst(String regex,String replacement)

    替换首个内容

    字符串拆分

    01

    public String[] split(String regex)

    将字符串全部拆分

    02

    public String[] split(String regex,int limit)

    将字符串部分拆分,该数组长度就是limit

    字符串截取

    01

    public String substring(int beginIndex)

    从指定索引截取到结尾

    02

    public String substring(int beginIndex,int endIndex)

    截取部分内容

    其他操作

    01

    public String trim()

    去掉字符串中的左右空格,保留中间空格

    02

    public String toUpperCase()

    字符串转大写

    03

    public String toLowerCase()

    字符串转小写

    04

    public String interm()

    字符串入对象池

    05

    public String concat(String str)

    字符串连接,等同于”+”

    06

    public int length()

    取得字符串长度

    07

    public boolean inEmpty()

    判断是否为空(不是null,而是长度为空)

  • 相关阅读:
    全国计算机等级考试二级教程-C语言程序设计_第10章_字符串
    网易云课堂_程序设计入门-C语言_第六章:数组_2鞍点
    arcgis api for silverlight开发系列之二:缓存图层与动态图层及图层总结 .
    VS2010程序打包操作(超详细的)
    地图三要素
    创业建议
    写代码时,必须注意“异常处理”
    WPF——RenderTransform特效
    MVVM特点、源(数据)与目标(如:控件等)的映射
    使用触发器定义 WPF 控件的行为
  • 原文地址:https://www.cnblogs.com/attentle/p/8735274.html
Copyright © 2020-2023  润新知