黑马程序员技术交流社区

标题: String类总结 2 (重发的帖子)不足之处望小伙伴们指出! [打印本页]

作者: oumentg    时间: 2016-2-26 22:39
标题: String类总结 2 (重发的帖子)不足之处望小伙伴们指出!


3.
转换功能:


byte[] getbytes(): 把字符串转换为字节数组

byte[]   getBytes(Charset charset)
char[] toCharArray(): 把字符串转换为字符数组


void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)
static String copyValueOf(char[] data)  返回指定数组中表示该字符序列的 String。
static String copyValueOf(char[] data, int offset, int count) :  返回指定数组中表示该字符序列的 String。   



static String valueOf(char[] chs): 把字符数组转成字符串。
static String valueOf(char[] data, int offset, int count)
static String valueOf()可以 ( boolean, char, int, long, double, float, Object, char[ ])8种类型的数据转换为字符串



String toLowerCase(): 转小写
String toUpperCase(): 转大写


String concat(String str): 拼接字符串 (concatenate)


4.比较功能
int compareTo(String str): 按字典顺序比较两个字符串int compareToIgnoreCase(String str)



5.
替换功能:
String replace(char old, char new):  把字符串里的某个字符替换为新字符
String replace(String old, String new): 把字符串里的指定子串替换为新子串
String replace(CharSequence target, CharSequence replacement)
          使用指定的字面值替换序列替换此字符串所有匹配字面值目标序列的子字符串。
String replaceAll(String regex, String replacement)
          使用给定的 replacement 替换此字符串所有匹配给定的正则表达式的子字符串。
String replaceFirst(String regex, String replacement)
          使用给定的 replacement 替换此字符串匹配给定的正则表达式的第一个子字符串。
6.
除去字符串两端空白
String trim(): 除去字符串两端空白

7.
String[] split(String regex)
          根据给定正则表达式的匹配拆分此字符串。


8.
使用指定的格式字符串和参数返回一个格式化字符串。
static String format(String format, Object... args)

9.
void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)
          将字符从此字符串复制到目标字符数组。


10.
int hashCode(): Stirng重写了hashCode()方法: s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]
          返回此字符串的哈希码。


11.
String toString()
          返回此对象本身(它已经是一个字符串!)。









欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2