string和stringbuillder的区别和用法 c

 我来答
缘Lai如茨
2016-08-08 · TA获得超过8631个赞
知道大有可为答主
回答量:7534
采纳率:92%
帮助的人:595万
展开全部
String 简介
String 是java中的字符串,它继承于CharSequence。
String类所包含的API接口非常多。为了便于今后的使用,我对String的API进行了分类,并都给出的演示程序。
String 和 CharSequence 关系
String 继承于CharSequence,也就是说String也是CharSequence类型。
CharSequence是一个接口,它只包括length(), charAt(int index), subSequence(int start, int end)这几个API接口。除了String实现了CharSequence之外,StringBuffer和StringBuilder也实现了CharSequence接口。
需要说明的是,CharSequence就是字符序列,String, StringBuilder和StringBuffer本质上都是通过字符数组实现的!

StringBuilder 和 StringBuffer 的区别
StringBuilder 和 StringBuffer都是可变的字符序列。它们都继承于AbstractStringBuilder,实现了CharSequence接口。
但是,StringBuilder是非线程安全的,而StringBuffer是线程安全的。

它们之间的关系图如下:

更多关于“StringBuilder”的内容,请参考:http://www.cnblogs.com/skywang12345/p/string02.html
更多关于“StringBuffer”的内容,请参考 :http://www.cnblogs.com/skywang12345/p/string03.html

String 函数列表

public String()
public String(String original)
public String(char[] value)
public String(char[] value, int offset, int count)
public String(byte[] bytes)
public String(byte[] bytes, int offset, int length)
public String(byte[] ascii, int hibyte)
public String(byte[] ascii, int hibyte, int offset, int count)
public String(byte[] bytes, String charsetName)
public String(byte[] bytes, int offset, int length, String charsetName)
public String(byte[] bytes, Charset charset)
public String(byte[] bytes, int offset, int length, Charset charset)
public String(int[] codePoints, int offset, int count)
public String(StringBuffer buffer)
public String(StringBuilder builder)

public char charAt(int index)
public int codePointAt(int index)
public int codePointBefore(int index)
public int codePointCount(int beginIndex, int endIndex)
public int compareTo(String anotherString)
public int compareToIgnoreCase(String str)
public String concat(String str)
public boolean contains(CharSequence s)
public boolean contentEquals(StringBuffer sb)
public boolean contentEquals(CharSequence cs)
public static String copyValueOf(char[] data, int offset, int count)
public static String copyValueOf(char[] data)
public boolean endsWith(String suffix)
public boolean equals(Object anObject)
public boolean equalsIgnoreCase(String anotherString)
public static String format(String format, Object[] args)
public static String format(Locale l, String format, Object[] args)
public int hashCode()
public int indexOf(int ch)
public int indexOf(int ch, int fromIndex)
public int indexOf(String str)
public int indexOf(String str, int fromIndex)
public String intern()
public int lastIndexOf(int ch)
public int lastIndexOf(int ch, int fromIndex)
public int lastIndexOf(String str)
public int lastIndexOf(String str, int fromIndex)
public int length()
public boolean matches(String regex)
public int offsetByCodePoints(int index, int codePointOffset)
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 String replace(char oldChar, char newChar)
public String replace(CharSequence target, CharSequence replacement)
public String replaceAll(String regex, String replacement)
public String replaceFirst(String regex, String replacement)
public String[] split(String regex, int limit)
public String[] split(String regex)
public boolean startsWith(String prefix, int toffset)
public boolean startsWith(String prefix)
public CharSequence subSequence(int beginIndex, int endIndex)
public String substring(int beginIndex)
public String substring(int beginIndex, int endIndex)
public char[] toCharArray()
public String toLowerCase(Locale locale)
public String toLowerCase()
public String toString()
public String toUpperCase(Locale locale)
public String toUpperCase()
public String trim()
public static String valueOf(Object obj)
public static String valueOf(char[] data)
public static String valueOf(char[] data, int offset, int count)
public static String valueOf(boolean b)
public static String valueOf(char c)
public static String valueOf(int i)
public static String valueOf(long l)
public static String valueOf(float f)
public static String valueOf(double d)
public void getBytes(int srcBegin, int srcEnd, byte[] dst, int dstBegin)
public byte[] getBytes(String charsetName)
public byte[] getBytes(Charset charset)
public byte[] getBytes()
public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)
public boolean isEmpty()
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式