String.substring 和String.subSequence

subsequece和string没什么区别,subsequece的实现调用了substring


* @since 1.4
     * @spec JSR-51
     */
    public CharSequence subSequence(int beginIndex, int endIndex) {
        return this.substring(beginIndex, endIndex);
    }
CharSequece是一个接口
public interface CharSequence {

    int length();//长度属性

    
    char charAt(int index);//获取第几个字符串

   
    CharSequence subSequence(int start, int end);//截取字符串

   
    public String toString();//转为String

}
String实现这个接口

public final class String
    implements java.io.Serializable, Comparable, CharSequence
{
    /** The value is used for character storage. */
    private final char value[];

    ……
   }

你可能感兴趣的:(java杂记)