String类常用方法(Java)

字符串与字符

No.方法名称类型描述
01public String(char[] value)构造将一个字符数组的全部内容转为字符串
02public String(char[] value,int offset,int count)方法

将部分字符数组转为字符串,参数的作用如下:

    offset:字符数组的操作索引位置

    count:要操作的字符数组的内容数量

03public char charAt(int index)方法获取指定索引位置上的字符内容
04public char[] toCharArray()方法将字符串转为字符数组

字符串与字节

No.方法名称类型描述
01public String(byte[] bytes)构造将接收的全部字节数组转为字符串
02public String(byte[] bytes,int offset,int length)方法将部分字节数组转成字符串
03public byte[] getBytes()方法将字符串转为字节数组
04public byte[] getBytes(String charsetName)throws UnsuportedEncodingException方法实现编码转换

字符串比较

No.方法名称类型描述
01public boolean equals(String anObject)方法区分大小写比较
02public boolean equalsIgnoreCase(String anotherString)方法忽略大小写
03public int compareTo(String anotherString)方法比较大小关系
04public int compareToIgnoreCase(String str)方法忽略大小实现关系比较

字符串查找

No.方法名称类型描述
01public boolean contains(String s)方法查找指定的子字符串是否存在
02public int indexOf(String str)方法从首部查找指定子字符串的位置,找不到返回-1
03public int indexOf(String str,int fromIndex) 方法从指定位置查找子字符串的位置,找不到返回-1
04public int lastIndexOf(String str)方法从后向前查找子字符串的位置
05public int lastIndexOf(String str,int fromIndex)方法从指定位置由后向前查找子字符串的位置
06public boolean startsWith(String prefix)方法是否以指定的字符串开头
07public boolean startsWith(String prefix,int toffset)方法是否在指定的索引位置开始以指定的字符串开头
08public boolean endsWith(String suffix)方法是否以指定的字符串结尾

字符串截取

No.方法名称类型描述
01public String substring(int beginIndex)方法从指定索引位置截取到结尾
02public String substring(int beginIndex,int endIndex)方法截取指定索引范围的子字符串

字符串替换

No.方法名称类型描述
01public String replaceAll(String regex,String replacement)方法字符串全部替换
02public  String replaceFirst(String regex,String replacement)方法替换首个内容

字符串拆分

No.方法名称类型描述
01public String[] split(String regex)方法全部拆分
02public String[] split(String regex,int limit)方法部分拆分,其中limit表示的数组拆分后的长度

其他字符串操作

No.方法名称类型描述
01public String intern()方法对象池保存
02public boolean isEmpty()方法判断是否为空字符串(不是null)
03public int length()方法获取字符串长度
04public String trim()方法去掉左右空格
05public String toUpperCase()方法转大写
06public String toLowerCase()方法转小写
07public String concat(String str)方法字符串连接
08public static String format(String format,数据类型...args)方法字符串格式化方法,使用格式化标记进行处理

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值