String类有两个私有的变量,字符数组value,和整型变量hash(默认为0)。
1 /** The value is used for character storage. */ 2 private final char value[]; 3 4 /** Cache the hash code for the string */ 5 private int hash; // Default to 0
下面对一些常用方法进行分析。
length()
1 /** 2 * Returns the length of this string. 3 * The length is equal to the number of <a href="Character.html#unicode">Unicode 4 * code units</a> in the string. 5 * 6 * @return the length of the sequence of characters represented by this 7 * object. 8 */ 9 public int length() { 10 return value.length; 11 }
、isEmpty()、charAt(int index)、equals(Object anObject)、hashCode()、indexOf(int ch)、substring(int beginIndex)、concat(String str)、
replace(char oldChar, char newChar) 、contains(CharSequence s)、
原文:https://www.cnblogs.com/DamonGeng/p/10480239.html