Java Api系列之String方法综述(JDK1.7)

以下内容均为JDK中文文档中内容,仅做学习参考使用:http://tool.oschina.net/apidocs/apidoc?api=jdk-zh
public int length()
返回此字符串的长度。(接口CharSequeue中的length方法)
public boolean isEmpty()
当且仅当length()为0时返回 true
public char charAt(int index)
返回指定索引处的char值。(接口CharSequeue中的length方法)
public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)
将字符从此字符串复制到目标字符数组。
public boolean equals(Object anObject)
将此字符串与指定的对象比较。
public boolean contentEquals(StringBuffer sb)
将此字符串与指定的StringBuffer比较。
public boolean contentEquals(CharSequence cs)
将此字符串与指定的CharSequence比较。
public boolean equalsIgnoreCase(String anotherString)
将此 String 与另一个String比较,不考虑大小写。
public int compareTo(String anotherString)
按字典顺序比较两个字符串。该比较基于字符串中各个字符的Unicode值。
public int compareToIgnoreCase(String str)
按字典顺序比较两个字符串,不考虑大小写。
public String replace(char oldChar, char newChar)
返回一个新的字符串,它是通过用newChar替换此字符串中出现的所有oldChar得到的。
public String replace(CharSequence target,CharSequence replacement)
使用指定的字面值替换序列替换此字符串所有匹配字面值目标序列的子字符串。
public String replaceFirst(String regex, String replacement)
使用给定的replacement替换此字符串匹配给定的正则表达式的第一个子字符串。
public String replaceAll(String regex,String replacement)
使用给定的 replacement 替换此字符串所有匹配给定的正则表达式的子字符串。

static String valueOf(boolean b)
返回 boolean 参数的字符串表示形式。
static String valueOf(char c)
返回 char 参数的字符串表示形式。
static String valueOf(char[] data)
返回 char 数组参数的字符串表示形式。
static String valueOf(char[] data, int offset, int count)
返回char 数组参数的特定子数组的字符串表示形式。
static String valueOf(double d)
返回double 参数的字符串表示形式。
static String valueOf(float f)
返回float 参数的字符串表示形式。
static String valueOf(int i)
返回int 参数的字符串表示形式。
static String valueOf(long l)
返回long 参数的字符串表示形式。
static String valueOf(Object obj)
返回Object 参数的字符串表示形式。

int indexOf(int ch) 
返回指定字符在此字符串中第一次出现处的索引。
int indexOf(int ch, int fromIndex)
返回在此字符串中第一次出现指定字符处的索引,从指定的索引开始搜索。
int indexOf(String str)
返回指定子字符串在此字符串中第一次出现处的索引。
int indexOf(String str, int fromIndex)
返回指定子字符串在此字符串中第一次出现处的索引,从指定的索引开始。
int lastIndexOf(int ch)
返回指定字符在此字符串中最后一次出现处的索引。
int lastIndexOf(int ch, int fromIndex)
返回指定字符在此字符串中最后一次出现处的索引,从指定的索引处开始进行反向搜索。
int lastIndexOf(String str)
返回指定子字符串在此字符串中最右边出现处的索引。
int lastIndexOf(String str, int fromIndex)
返回指定子字符串在此字符串中最后一次出现处的索引,从指定的索引开始反向搜索。

public char[] toCharArray()
将此字符串转换为一个新的字符数组。(转换为数组后可用Arrays.sort()进行排序操作)

public boolean contains(CharSequeue s)
当且仅当此字符串包含指定的 char 值序列时,返回 true。



 

public int codePointAt(int index)
返回指定索引处的字符(Unicode代码点)。
public int codePointBefore(int index)
返回指定索引之前的字符(Unicode代码点)
public int codePointCount(int beginIndex, int endIndex)
返回此String的指定文本范围中的Unicode代码点数。
public int offsetByCodePoints(int index, int codePointOffset)
返回此String中从给定的index处偏移 codePointOffset 个代码点的索引。
public byte[] getBytes(String charsetName) throws UnsupportedEndodingException
使用指定的字符集将此String编码为 byte 序列,并将结果存储到一个新的 byte 数组中。
public byte[] getBytes(Charset charset)
使用给定的charset将此String编码到byte序列,并将结果存储到新的byte数组。
public byte[] getBytes()
使用平台的默认字符集将此String编码为byte序列,并将结果存储到一个新的byte数组中。
public boolean regionMatches(int toffset, String other, int ooffset, int len)
测试两个字符串区域是否相等。
public boolean regionMatches(boolean ignoreCase, int toffset, String other, int ooffset, int len)
测试两个字符串区域是否相等。
public boolean startsWith(String prefix, int toffset)
测试此字符串从指定索引开始的子字符串是否以指定前缀开始。
public boolean startsWith(String prefix)
测试此字符串是否以指定的前缀开始。
public boolean endsWith(String suffix)
测试此字符串是否以指定的后缀结束。





 






原文地址:https://www.cnblogs.com/liujinyao/p/4725586.html