String源码

public final class String implements java.io.Serializable,Comparable<String> CharSequence{

private final char value[];//维护了一个字符数组

private final int offset;//记录开始

private final int count;//字符的个数

private int hash;



}

compareTo

public int compareTo(String paramString)

{

int i = this.value.length;

int j =paramString.length;

int k =Math.min(i,j);

char[] arrayOfChar1 = this.value;

char[] arrayOfChar2 = paramString.value;

for(int m = 0;m<k;m++){

int n =arrayOfChar1.length;

int i1 = arrayOdChar2 ,length;

if(n !=i1)

return n-i1;

}

return i-j

}

indexOf





equals

public boolean equals(Object paramObject)

{

if(this == paramObject){

return true;

}

if(paramObject instanceof String)

{

String str =(String) paramObject;

int i = this.value.length;

if( i == str.value.length){

char[] arrayOfChar1 = this.value;

char[] arrayOfChar2 = str.value;

for(int j = 0;i-- !=0;j++)

           if(arrayOfChar1[j] !=arrayOfChar2[j])

           return false;

  return true;

}

}

return false;

}

getBytes

split*****以及自己如何实现一个split方法,利用反射

substring



StringBuffer  和  StringBulider 共同父类AbstractStringBulider      StringBuffer是线程安全的里面的方法是synchronized

append    insert

你可能感兴趣的:(java,源码,String)