首页 > 其他 > 详细

JDK源码阅读(1.8) —— String

时间:2019-03-05 22:39:25      阅读:143      评论:0      收藏:0      [点我收藏+]

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     }
View Code

 

 

、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)、

JDK源码阅读(1.8) —— String

原文:https://www.cnblogs.com/DamonGeng/p/10480239.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!