一、String类
变量和类型 | 方法 | 描述 |
---|---|---|
char | charAt(int index) | 返回指定索引处的 |
IntStream | chars() | 返回 |
int | codePointAt(int index) | 返回指定索引处的字符(Unicode代码点)。 |
int | codePointBefore(int index) | 返回指定索引之前的字符(Unicode代码点)。 |
int | codePointCount(int beginIndex, int endIndex) | 返回此 |
IntStream | codePoints() | 返回此序列中的代码点值流。 |
int | compareTo(String anotherString) | 按字典顺序比较两个字符串。 |
int | compareToIgnoreCase(String str) | 按字典顺序比较两个字符串,忽略大小写差异。 |
String | concat(String str) | 将指定的字符串连接到此字符串的末尾。 |
boolean | contains(CharSequence s) | 当且仅当此字符串包含指定的char值序列时,才返回true。 |
boolean | contentEquals(CharSequence cs) | 将此字符串与指定的 |
boolean | contentEquals(StringBuffer sb) | 将此字符串与指定的 |
static String | copyValueOf(char[] data) | 相当于 |
static String | copyValueOf(char[] data, int offset, int count) | |
boolean | endsWith(String suffix) | 测试此字符串是否以指定的后缀结尾。 |
boolean | equals(Object anObject) | 将此字符串与指定的对象进行比较。 |
boolean | equalsIgnoreCase(String anotherString) | 将此 |
static String | format(String format, Object... args) | 使用指定的格式字符串和参数返回格式化字符串。 |
static String | format(Locale l, String format, Object... args) | 使用指定的语言环境,格式字符串和参数返回格式化的字符串。 |
byte[] | getBytes() | 使用平台的默认字符集将此 |
void | getBytes(int srcBegin, int srcEnd, byte[] dst, int dstBegin) | 已过时。 此方法无法将字符正确转换为字节。 |
byte[] | getBytes(String charsetName) | 使用命名的字符集将此 |
byte[] | getBytes(Charset charset) | 使用给定的charset将此 |
void | getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin) | 将此字符串中的字符复制到目标字符数组中。 |
int | hashCode() | 返回此字符串的哈希码。 |
int | indexOf(int ch) | 返回指定字符第一次出现的字符串中的索引。 |
int | indexOf(int ch, int fromIndex) | 返回指定字符第一次出现的此字符串中的索引,从指定索引处开始搜索。 |
int | indexOf(String str) | 返回指定子字符串第一次出现的字符串中的索引。 |
int | indexOf(String str, int fromIndex) | 从指定的索引处开始,返回指定子字符串第一次出现的字符串中的索引。 |
String | intern() | 返回字符串对象的规范表示。 |
boolean | isBlank() | 如果字符串为空或仅包含 |
boolean | isEmpty() | 返回 |
static String | join(CharSequence delimiter, CharSequence... elements) | 返回由 |
static String | join(CharSequence delimiter, Iterable<? extends CharSequence> elements) | 返回由 |
int | lastIndexOf(int ch) | 返回指定字符最后一次出现的字符串中的索引。 |
int | lastIndexOf(int ch, int fromIndex) | 返回指定字符最后一次出现的字符串中的索引,从指定的索引开始向后搜索。 |
int | lastIndexOf(String str) | 返回指定子字符串最后一次出现的字符串中的索引。 |
int | lastIndexOf(String str, int fromIndex) | 返回指定子字符串最后一次出现的字符串中的索引,从指定索引开始向后搜索。 |
int | length() | 返回此字符串的长度。 |
Stream<String> | lines() | 返回从此字符串中提取的行的流,由行终止符分隔。 |
boolean | matches(String regex) | 判断此字符串是否与给定的 regular expression匹配。 |
int | offsetByCodePoints(int index, int codePointOffset) | 返回此 |
boolean | regionMatches(boolean ignoreCase, int toffset, String other, int ooffset, int len) | 测试两个字符串区域是否相等。 |
boolean | regionMatches(int toffset, String other, int ooffset, int len) | 测试两个字符串区域是否相等。 |
String | repeat(int count) | 返回一个字符串,其值为此字符串的串联重复 |
String | replace(char oldChar, char newChar) | 返回从替换所有出现的导致一个字符串 |
String | replace(CharSequence target, CharSequence replacement) | 将此字符串中与文字目标序列匹配的每个子字符串替换为指定的文字替换序列。 |
String | replaceAll(String regex, String replacement) | 将给定替换的给定 regular expression匹配的此字符串的每个子字符串替换。 |
String | replaceFirst(String regex, String replacement) | 将给定替换的给定 regular expression匹配的此字符串的第一个子字符串替换。 |
String[] | split(String regex) | 将此字符串拆分为给定 regular expression的匹配 项 。 |
String[] | split(String regex, int limit) | 将此字符串拆分为给定 regular expression的匹配 项 。 |
boolean | startsWith(String prefix) | 测试此字符串是否以指定的前缀开头。 |
boolean | startsWith(String prefix, int toffset) | 测试从指定索引开始的此字符串的子字符串是否以指定的前缀开头。 |
String | strip() | 返回一个字符串,其值为此字符串,并删除了所有前导和尾随 |
String | stripLeading() | 返回一个字符串,其值为此字符串,并删除了所有前导 |
String | stripTrailing() | 返回一个字符串,其值为此字符串,并删除所有尾随 |
CharSequence | subSequence(int beginIndex, int endIndex) | 返回作为此序列的子序列的字符序列。 |
String | substring(int beginIndex) | 返回一个字符串,该字符串是此字符串的子字符串。 |
String | substring(int beginIndex, int endIndex) | 返回一个字符串,该字符串是此字符串的子字符串。 |
char[] | toCharArray() | 将此字符串转换为新的字符数组。 |
String | toLowerCase() | 使用默认语言环境的规则将此 |
String | toLowerCase(Locale locale) | 使用给定 |
String | toString() | 这个对象(已经是一个字符串!) |
String | toUpperCase() | 使用默认语言环境的规则将此 |
String | toUpperCase(Locale locale) | 使用给定 |
String | trim() | 返回一个字符串,其值为此字符串,删除了所有前导和尾随空格,其中space被定义为其代码点小于或等于 |
static String | valueOf(boolean b) | 返回 |
static String | valueOf(char c) | 返回 |
static String | valueOf(char[] data) | 返回 |
static String | valueOf(char[] data, int offset, int count) | 返回 |
static String | valueOf(double d) | 返回 |
static String | valueOf(float f) | 返回 |
static String | valueOf(int i) | 返回 |
static String | valueOf(long l) | 返回 |
static String | valueOf(Object obj) | 返回 |
二、StringBuilder类
字符串拼接和反转会用StringBuilder
变量和类型 | 方法 | 描述 |
---|---|---|
StringBuilder | append(boolean b) | 将 |
StringBuilder | append(char c) | 将 |
StringBuilder | append(char[] str) | 将 |
StringBuilder | append(char[] str, int offset, int len) | 将 |
StringBuilder | append(double d) | 将 |
StringBuilder | append(float f) | 将 |
StringBuilder | append(int i) | 将 |
StringBuilder | append(long lng) | 将 |
StringBuilder | append(CharSequence s) | 将指定的字符序列追加到此 |
StringBuilder | append(CharSequence s, int start, int end) | 将指定的 |
StringBuilder | append(Object obj) | 追加 |
StringBuilder | append(String str) | 将指定的字符串追加到此字符序列。 |
StringBuilder | append(StringBuffer sb) | 将指定的 |
StringBuilder | appendCodePoint(int codePoint) | 将 |
int | capacity() | 返回当前容量。 |
char | charAt(int index) | 返回指定索引处的此序列中的 |
IntStream | chars() | 返回 |
int | codePointAt(int index) | 返回指定索引处的字符(Unicode代码点)。 |
int | codePointBefore(int index) | 返回指定索引之前的字符(Unicode代码点)。 |
int | codePointCount(int beginIndex, int endIndex) | 返回此序列的指定文本范围内的Unicode代码点数。 |
IntStream | codePoints() | 返回此序列中的代码点值流。 |
int | compareTo(StringBuilder another) |
|
StringBuilder | delete(int start, int end) | 删除此序列的子字符串中的字符。 |
StringBuilder | deleteCharAt(int index) | 按此顺序删除指定位置的 |
void | ensureCapacity(int minimumCapacity) | 确保容量至少等于指定的最小值。 |
void | getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin) | 将字符从此序列复制到目标字符数组 |
int | indexOf(String str) | 返回指定子字符串第一次出现的字符串中的索引。 |
int | indexOf(String str, int fromIndex) | 从指定的索引处开始,返回指定子字符串第一次出现的字符串中的索引。 |
StringBuilder | insert(int offset, boolean b) | 将 |
StringBuilder | insert(int offset, char c) | 将 |
StringBuilder | insert(int offset, char[] str) | 将 |
StringBuilder | insert(int index, char[] str, int offset, int len) | 将 |
StringBuilder | insert(int offset, double d) | 将 |
StringBuilder | insert(int offset, float f) | 将 |
StringBuilder | insert(int offset, int i) | 将第二个 |
StringBuilder | insert(int offset, long l) | 将 |
StringBuilder | insert(int dstOffset, CharSequence s) | 将指定的 |
StringBuilder | insert(int dstOffset, CharSequence s, int start, int end) | 将指定的 |
StringBuilder | insert(int offset, Object obj) | 将 |
StringBuilder | insert(int offset, String str) | 将字符串插入此字符序列。 |
int | lastIndexOf(String str) | 返回指定子字符串最后一次出现的字符串中的索引。 |
int | lastIndexOf(String str, int fromIndex) | 返回指定子字符串最后一次出现的字符串中的索引,从指定索引开始向后搜索。 |
int | length() | 返回长度(字符数)。 |
int | offsetByCodePoints(int index, int codePointOffset) | 返回此序列中的索引,该索引从给定的 |
StringBuilder | replace(int start, int end, String str) | 使用指定的 |
StringBuilder | reverse() | 导致此字符序列被序列的反向替换。 |
void | setCharAt(int index, char ch) | 指定索引处的字符设置为 |
void | setLength(int newLength) | 设置字符序列的长度。 |
CharSequence | subSequence(int start, int end) | 返回一个新的字符序列,它是该序列的子序列。 |
String | substring(int start) | 返回一个新的 |
String | substring(int start, int end) | 返回一个新的 |
void | trimToSize() | 尝试减少用于字符序列的存储空间。三、StringBuffer类 |
三、StringBuffer类
StringBuffer | append(boolean b) | 将 |
---|---|---|
StringBuffer | append(char c) | 将 |
StringBuffer | append(char[] str) | 将 |
StringBuffer | append(char[] str, int offset, int len) | 将 |
StringBuffer | append(double d) | 将 |
StringBuffer | append(float f) | 将 |
StringBuffer | append(int i) | 将 |
StringBuffer | append(long lng) | 将 |
StringBuffer | append(CharSequence s) | 将指定的 |
StringBuffer | append(CharSequence s, int start, int end) | 将指定的 |
StringBuffer | append(Object obj) | 追加 |
StringBuffer | append(String str) | 将指定的字符串追加到此字符序列。 |
StringBuffer | append(StringBuffer sb) | 将指定的 |
StringBuffer | appendCodePoint(int codePoint) | 将 |
int | capacity() | 返回当前容量。 |
char | charAt(int index) | 返回指定索引处的此序列中的 |
IntStream | chars() | 返回 |
int | codePointAt(int index) | 返回指定索引处的字符(Unicode代码点)。 |
int | codePointBefore(int index) | 返回指定索引之前的字符(Unicode代码点)。 |
int | codePointCount(int beginIndex, int endIndex) | 返回此序列的指定文本范围内的Unicode代码点数。 |
IntStream | codePoints() | 返回此序列中的代码点值流。 |
int | compareTo(StringBuffer another) |
|
StringBuffer | delete(int start, int end) | 删除此序列的子字符串中的字符。 |
StringBuffer | deleteCharAt(int index) | 按此顺序删除指定位置的 |
void | ensureCapacity(int minimumCapacity) | 确保容量至少等于指定的最小值。 |
void | getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin) | 将字符从此序列复制到目标字符数组 |
int | indexOf(String str) | 返回指定子字符串第一次出现的字符串中的索引。 |
int | indexOf(String str, int fromIndex) | 从指定的索引处开始,返回指定子字符串第一次出现的字符串中的索引。 |
StringBuffer | insert(int offset, boolean b) | 将 |
StringBuffer | insert(int offset, char c) | 将 |
StringBuffer | insert(int offset, char[] str) | 将 |
StringBuffer | insert(int index, char[] str, int offset, int len) | 将 |
StringBuffer | insert(int offset, double d) | 将 |
StringBuffer | insert(int offset, float f) | 将 |
StringBuffer | insert(int offset, int i) | 将第二个 |
StringBuffer | insert(int offset, long l) | 将 |
StringBuffer | insert(int dstOffset, CharSequence s) | 将指定的 |
StringBuffer | insert(int dstOffset, CharSequence s, int start, int end) | 将指定的 |
StringBuffer | insert(int offset, Object obj) | 将 |
StringBuffer | insert(int offset, String str) | 将字符串插入此字符序列。 |
int | lastIndexOf(String str) | 返回指定子字符串最后一次出现的字符串中的索引。 |
int | lastIndexOf(String str, int fromIndex) | 返回指定子字符串最后一次出现的字符串中的索引,从指定索引开始向后搜索。 |
int | offsetByCodePoints(int index, int codePointOffset) | 返回此序列中的索引,该索引从给定的 |
StringBuffer | replace(int start, int end, String str) | 使用指定的 |
StringBuffer | reverse() | 导致此字符序列被序列的反向替换。 |
void | setCharAt(int index, char ch) | 指定索引处的字符设置为 |
void | setLength(int newLength) | 设置字符序列的长度。 |
CharSequence | subSequence(int start, int end) | 返回一个新的字符序列,它是该序列的子序列。 |
String | substring(int start) | 返回一个新的 |
String | substring(int start, int end) | 返回一个新的 |
void | trimToSize() | 尝试减少用于字符序列的存储空间。 |
四、StringJoiner类
适用于字符串拼接,比StringBuilder更简洁
构造方法
public StringJoiner(间隔符号)指定拼接时的间隔符号
public StringJoiner(间隔符号,开始符号,结束符号)
StringJoiner | add(CharSequence newElement) | 将给定的副本 括号里面的是字符串 |
---|---|---|
int | length() | 返回此 |
StringJoiner | merge(StringJoiner other) | 如果非空,则添加给定 |
StringJoiner | setEmptyValue(CharSequence emptyValue) | 设置在确定此 |
String | toString() | 返回当前值,包括 |