一, 字符串数组
构造函数:
String[] array = new String[5];
String[] array =new String[] {“aa”,”bb”,”cc”};
String[] array = {“aa”,”bb”,”cc”};
字符串数组也被看做对象:
属性:length (区别于字符串的方法length())
常用方法:void System.arraycopy(object[] from,intfromIndex, object[] to,int fromIndex,int count),系统的一个静态方法
二,字符串缓存类StringBuffer
String类对象一旦声明就不能改变,StringBuffer缓存类实现了可变字符序列。
StringBuffer上的基本操作是append和insert方法,它们接受任意的数据,把所给数据转化为一个字符串,并把这个字符串添加到缓冲区的末端或者插到指定地方。
public final class StringBuffer
extends Object
implements Serializable, CharSequence
其他方法:
StringBuffer转化为String对象:toString()
String
|
toString() Returns a string representing the data in this sequence.
|
StringBuffer的扩充appand():
等等…….
任意类型都将被转化为字符串加入缓存末端
StringBuffer的插入insert():
StringBuffer
|
insert(int offset, char[] str) Inserts the string representation of the char array argument into this sequence.
|
StringBuffer
|
insert(int index, char[] str, int offset, int len) Inserts the string representation of a subarray of the str array argument into this sequence.
|
等等……
典型的其他操作:
int
|
length() Returns the length (character count).
|
char
|
charAt(int index) Returns the char value in this sequence at the specified index.
|
String
|
substring(int start) Returns a new String that contains a subsequence of characters currently contained in this character sequence.
|
int
|
indexOf(String str) Returns the index within this string of the first occurrence of the specified substring.
|
StringBuffer
|
replace(int start, int end, String str) Replaces the characters in a substring of this sequence with characters in the specified String.
|
StringBuffer
|
delete(int start, int end) Removes the characters in a substring of this sequence.
|
等等…..