首页 > 其他 > 详细

String类常用方法

时间:2019-05-21 21:40:49      阅读:97      评论:0      收藏:0      [点我收藏+]

No.

方法名称

类型

描述

01

public String?(char[] value)

构造

将一个字符数组的全部内容转为字符串

02

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

方法

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

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

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

03

public char charAt?(int index)

方法

获取指定索引位置上的字符内容

04

public char[] toCharArray()

方法

将字符串转为字符数组

05

public String?(byte[] bytes)

构造

将接收的全部字节数组转为字符串

06

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

方法

将部分字节数组转为字符串

07

public byte[] getBytes()

方法

将字符串转为字节数组

08

public byte[] getBytes?(String charsetName) throws UnsupportedEncodingException

方法

实现编码转换

09

public boolean equals?(String anObject)

方法

区分大小写比较

10

public boolean equalsIgnoreCase?(String anotherString)

方法

忽略大小写比较

11

public int compareTo?(String anotherString)

方法

比较大小关系

12

public int compareToIgnoreCase?(String str)

方法

忽略大小实现关系比较

13

public boolean contains?(String s)

方法

查找指定的子字符串是否存在

14

public int indexOf?(String str)

方法

从首部查找指定子字符串的位置,找不到返回-1

15

public int indexOf?(String str, int fromIndex)

方法

从指定位置查找子字符串的位置,找不到返回-1

16

public int lastIndexOf?(String str)

方法

从后向前查找子字符串的位置

17

public int lastIndexOf?(String str, int fromIndex)

方法

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

18

public boolean startsWith?(String prefix)

方法

是否以指定的字符串开头

19

public boolean startsWith?(String prefix, int toffset)

方法

是否在指定的索引位置开始以指定的字符串开头

20

public boolean endsWith?(String suffix)

方法

是否以指定的字符串结尾

21

public String substring?(int beginIndex)

方法

从指定索引位置截取到结尾

22

public String substring?(int beginIndex, int endIndex)

方法

截取指定索引范围的子字符串

23

public String replaceAll?(String regex, String replacement)

方法

字符串全部替换

24

public String replaceFirst?(String regex, String replacement)

方法

替换首个内容

25

public String[] split?(String regex)

方法

全部拆分

26

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

方法

部分拆分,其中limit表示的数组拆分后的长度

27

public String intern()

方法

对象池保存

28

public boolean isEmpty()

方法

判断是否为空字符串(不是null)

29

public int length()

方法

获取字符串长度

30

public String trim()

方法

去掉左右空格

31

public String toUpperCase()

方法

转大写

32

public String toLowerCase()

方法

转小写

33

public String concat?(String str)

方法

字符串连接

34

public static String format?(String format, 数据类型... args)

方法

字符串格式化方法,使用格式化标记进行处理

 

String类常用方法

原文:https://www.cnblogs.com/luliang888/p/10902485.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!