CharSequence与String都能用于定义字符串,但CharSequence的值是可读可写序列,而String的值是只读序列。
CharSequence
这是一个接口,代表的是一个有序字符集合,这个接口包含的方法有:charAt(int index),toString(),length(),subSequence(int start,int end).
CharSequence是一个借口,不能用new进行实例化,但是可以用下边的方法进行来进行实例化:
CharSequence mCharSequence="ban";
public interface CharSequence {
/**
* Returns the number of characters in this sequence.
*
* @return the number of characters.
*/
public int length();
/**
* Returns the character at {@code index}.
* @throws IndexOutOfBoundsException if {@code index < 0} or {@code index >= length()}.
*/
public char charAt(int index);
/**
* Returns a {@code CharSequence} from the {@code start} index (inclusive)
* to the {@code end} index (exclusive) of this sequence.
*
* @param start
* the start offset of the sub-sequence. It is inclusive, that
* is, the index of the first character that is included in the
* sub-sequence.
* @param end
* the end offset of the sub-sequence. It is exclusive, that is,
* the index of the first character after those that are included
* in the sub-sequence
* @return the requested sub-sequence.
* @throws IndexOutOfBoundsException
* if {@code start < 0}, {@code end < 0}, {@code start > end},
* or if {@code start} or {@code end} are greater than the
* length of this sequence.
*/
public CharSequence subSequence(int start, int end);
/**
* Returns a string with the same characters in the same order as in this
* sequence.
*
* @return a string based on this sequence.
*/