Java String 类 第2页

Java startsWith() 方法

阅读(466)

startsWith() 方法用于检测字符串是否以指定的前缀开始。 语法 public boolean startsWith(String prefix, int toffset) 或 public boolean startsWith(S...

Java split() 方法

阅读(497)

split() 方法根据匹配给定的正则表达式来拆分字符串。 注意: . 、 $、 | 和 * 等转义字符,必须得加 \。 注意:多个分隔符,可以用 | 作为连字符。 语法 public String[] split(String regex...

Java replaceFirst() 方法

阅读(402)

replaceFirst() 方法使用给定的参数 replacement 替换字符串第一个匹配给定的正则表达式的子字符串。 语法 public String replaceFirst(String regex, String replace...

Java replaceAll() 方法

阅读(559)

replaceAll() 方法使用给定的参数 replacement 替换字符串所有匹配给定的正则表达式的子字符串。 语法 public String replaceAll(String regex, String replacement)...

Java replace() 方法

阅读(610)

replace() 方法通过用 newChar 字符替换字符串中出现的所有 searchChar 字符,并返回替换后的新字符串。 语法 public String replace(char searchChar, char newChar)...

Java regionMatches() 方法

阅读(456)

regionMatches() 方法用于检测两个字符串在一个区域内是否相等。 语法 public boolean regionMatches(int toffset, String other, int ooffset, int len) ...

Java matches() 方法

阅读(448)

matches() 方法用于检测字符串是否匹配给定的正则表达式。 调用此方法的 str.matches(regex) 形式与以下表达式产生的结果完全相同: Pattern.matches(regex, str) 语法 public bool...

Java String length() 方法

阅读(490)

length() 方法用于返回字符串的长度。 空字符串的长度返回 0。 语法 public int length() 参数 无 返回值 返回字符串长度。 实例 以下实例演示了 length() 方法的使用: 实例 public class ...

Java lastIndexOf() 方法

阅读(425)

lastIndexOf() 方法有以下四种形式: public int lastIndexOf(int ch): 返回指定字符在此字符串中最后一次出现处的索引,如果此字符串中没有这样的字符,则返回 -1。 public int lastIn...

Java intern() 方法

阅读(478)

intern() 方法返回字符串对象的规范化表示形式。 它遵循以下规则:对于任意两个字符串 s 和 t,当且仅当 s.equals(t) 为 true 时,s.intern() == t.intern() 才为 true。 语法 publi...