Java String 类 第3页

Java String indexOf() 方法

阅读(503)

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

Java hashCode() 方法

阅读(494)

hashCode() 方法用于返回字符串的哈希码。 字符串对象的哈希码根据以下公式计算: s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1] 使用 int 算法,这里 s[i] 是字符串的第 i 个字符...

Java getChars() 方法

阅读(491)

getChars() 方法将字符从字符串复制到目标字符数组。 语法 public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin) 参数 srcBegin -...

Java getBytes() 方法

阅读(479)

getBytes() 方法有两种形式: getBytes(String charsetName): 使用指定的字符集将字符串编码为 byte 序列,并将结果存储到一个新的 byte 数组中。 getBytes(): 使用平台的默认字符集将字...

Java equalsIgnoreCase() 方法

阅读(750)

equalsIgnoreCase() 方法用于将字符串与指定的对象比较,不考虑大小写。 语法 public boolean equalsIgnoreCase(String anotherString) 参数 anObject -- 与字符串...

Java String equals() 方法

阅读(493)

equals() 方法用于将字符串与指定的对象比较。 String 类中重写了 equals() 方法用于比较两个字符串的内容是否相等。 语法 public boolean equals(Object anObject) 参数 anObje...

Java endsWith() 方法

阅读(415)

endsWith() 方法用于测试字符串是否以指定的后缀结束。 语法 public boolean endsWith(String suffix) 参数 suffix -- 指定的后缀。 返回值 如果参数表示的字符序列是此对象表示的字符序列...

Java copyValueOf() 方法

阅读(543)

copyValueOf() 方法有两种形式: public static String copyValueOf(char[] data): 返回指定数组中表示该字符序列的字符串。 public static String copyValue...

Java contentEquals() 方法

阅读(434)

contentEquals() 方法用于将此字符串与指定的 StringBuffer 比较。 语法 public boolean contentEquals(StringBuffer sb) 参数 sb -- 要与字符串比较的 String...

Java concat() 方法

阅读(467)

concat() 方法用于将指定的字符串参数连接到字符串上。 语法 public String concat(String s) 参数 s -- 要连接的字符串。 返回值 返回连接后的新字符串。 实例 public class Test {...