字符串与字符
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() | 方法 | 将字符串转为字符数组 |
字符串与字节
No. | 方法名称 | 类型 | 描述 |
---|---|---|---|
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 UnsuportedEncodingException | 方法 | 实现编码转换 |
字符串比较
No. | 方法名称 | 类型 | 描述 |
---|---|---|---|
01 | public boolean equals(String anObject) | 方法 | 区分大小写比较 |
02 | public boolean equalsIgnoreCase(String anotherString) | 方法 | 忽略大小写 |
03 | public int compareTo(String anotherString) | 方法 | 比较大小关系 |
04 | public int compareToIgnoreCase(String str) | 方法 | 忽略大小实现关系比较 |
字符串查找
No. | 方法名称 | 类型 | 描述 |
---|---|---|---|
01 | public boolean contains(String s) | 方法 | 查找指定的子字符串是否存在 |
02 | public int indexOf(String str) | 方法 | 从首部查找指定子字符串的位置,找不到返回-1 |
03 | public int indexOf(String str,int fromIndex) | 方法 | 从指定位置查找子字符串的位置,找不到返回-1 |
04 | public int lastIndexOf(String str) | 方法 | 从后向前查找子字符串的位置 |
05 | public int lastIndexOf(String str,int fromIndex) | 方法 | 从指定位置由后向前查找子字符串的位置 |
06 | public boolean startsWith(String prefix) | 方法 | 是否以指定的字符串开头 |
07 | public boolean startsWith(String prefix,int toffset) | 方法 | 是否在指定的索引位置开始以指定的字符串开头 |
08 | public boolean endsWith(String suffix) | 方法 | 是否以指定的字符串结尾 |
字符串截取
No. | 方法名称 | 类型 | 描述 |
---|---|---|---|
01 | public String substring(int beginIndex) | 方法 | 从指定索引位置截取到结尾 |
02 | public String substring(int beginIndex,int endIndex) | 方法 | 截取指定索引范围的子字符串 |
字符串替换
No. | 方法名称 | 类型 | 描述 |
---|---|---|---|
01 | public String replaceAll(String regex,String replacement) | 方法 | 字符串全部替换 |
02 | public String replaceFirst(String regex,String replacement) | 方法 | 替换首个内容 |
字符串拆分
No. | 方法名称 | 类型 | 描述 |
---|---|---|---|
01 | public String[] split(String regex) | 方法 | 全部拆分 |
02 | public String[] split(String regex,int limit) | 方法 | 部分拆分,其中limit表示的数组拆分后的长度 |
其他字符串操作
No. | 方法名称 | 类型 | 描述 |
---|---|---|---|
01 | public String intern() | 方法 | 对象池保存 |
02 | public boolean isEmpty() | 方法 | 判断是否为空字符串(不是null) |
03 | public int length() | 方法 | 获取字符串长度 |
04 | public String trim() | 方法 | 去掉左右空格 |
05 | public String toUpperCase() | 方法 | 转大写 |
06 | public String toLowerCase() | 方法 | 转小写 |
07 | public String concat(String str) | 方法 | 字符串连接 |
08 | public static String format(String format,数据类型...args) | 方法 | 字符串格式化方法,使用格式化标记进行处理 |