Skip to content

Commit

Permalink
Site updated: 2019-07-11 20:28:58
Browse files Browse the repository at this point in the history
  • Loading branch information
scyx committed Jul 11, 2019
1 parent 94a12ba commit 0ce5f25
Show file tree
Hide file tree
Showing 32 changed files with 50 additions and 58 deletions.
2 changes: 1 addition & 1 deletion 2019-3-18腾讯一面.html
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ <h2 id="3-18晚上9点-人生第一次面试-岗位:后台开发"><a href="#3-

<span class="post-meta-item-text">Site words total count&#58;</span>

<span title="Site words total count">7.5k</span>
<span title="Site words total count">7.7k</span>

</div>

Expand Down
2 changes: 1 addition & 1 deletion 2019/04/15/Java中接口和抽象类的区别/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ <h1 id="什么时候使用抽象类?什么时候使用接口?"><a href="#什

<span class="post-meta-item-text">Site words total count&#58;</span>

<span title="Site words total count">7.5k</span>
<span title="Site words total count">7.7k</span>

</div>

Expand Down
2 changes: 1 addition & 1 deletion 2019/04/16/Java排序算法之插入排序/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ <h2 id="什么是插入排序"><a href="#什么是插入排序" class="headerlin

<span class="post-meta-item-text">Site words total count&#58;</span>

<span title="Site words total count">7.5k</span>
<span title="Site words total count">7.7k</span>

</div>

Expand Down
2 changes: 1 addition & 1 deletion 2019/05/02/MySQL索引原理/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ <h2 id="建索引的几大原则"><a href="#建索引的几大原则" class="hea

<span class="post-meta-item-text">Site words total count&#58;</span>

<span title="Site words total count">7.5k</span>
<span title="Site words total count">7.7k</span>

</div>

Expand Down
2 changes: 1 addition & 1 deletion 2019/05/03/一文理解ThreadLocal/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ <h2 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</

<span class="post-meta-item-text">Site words total count&#58;</span>

<span title="Site words total count">7.5k</span>
<span title="Site words total count">7.7k</span>

</div>

Expand Down
2 changes: 1 addition & 1 deletion 2019/05/05/Springboot启动流程/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ <h2 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</

<span class="post-meta-item-text">Site words total count&#58;</span>

<span title="Site words total count">7.5k</span>
<span title="Site words total count">7.7k</span>

</div>

Expand Down
2 changes: 1 addition & 1 deletion 2019/05/09/牛客网刷题记录2019-5-9/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ <h2 id="下面哪个不属于HttpServletResponse接口完成的功能?"><a hre

<span class="post-meta-item-text">Site words total count&#58;</span>

<span title="Site words total count">7.5k</span>
<span title="Site words total count">7.7k</span>

</div>

Expand Down
2 changes: 1 addition & 1 deletion 2019/05/22/final关键字/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ <h2 id="注意"><a href="#注意" class="headerlink" title="注意"></a>注意</

<span class="post-meta-item-text">Site words total count&#58;</span>

<span title="Site words total count">7.5k</span>
<span title="Site words total count">7.7k</span>

</div>

Expand Down
2 changes: 1 addition & 1 deletion 2019/05/23/Springboot自动配置原理/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ <h2 id="Springboot的核心注解-SpringBootApplication"><a href="#Springboot的

<span class="post-meta-item-text">Site words total count&#58;</span>

<span title="Site words total count">7.5k</span>
<span title="Site words total count">7.7k</span>

</div>

Expand Down
2 changes: 1 addition & 1 deletion 2019/05/27/Java异常体系/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ <h2 id="异常的方法"><a href="#异常的方法" class="headerlink" title="

<span class="post-meta-item-text">Site words total count&#58;</span>

<span title="Site words total count">7.5k</span>
<span title="Site words total count">7.7k</span>

</div>

Expand Down
2 changes: 1 addition & 1 deletion 2019/05/28/ArrayList源码解读/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ <h2 id="fail-fast"><a href="#fail-fast" class="headerlink" title="fail-fast"></a

<span class="post-meta-item-text">Site words total count&#58;</span>

<span title="Site words total count">7.5k</span>
<span title="Site words total count">7.7k</span>

</div>

Expand Down
19 changes: 10 additions & 9 deletions 2019/07/11/String为啥不可变/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,12 @@
<meta property="og:site_name" content="Cyx&#39;s blog">
<meta property="og:description" content="经常说String不可变 String到底为啥不可变">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2019-07-11T12:27:41.870Z">
<meta property="og:image" content="https://scyx.github.io/images/String.png">
<meta property="og:updated_time" content="2019-07-11T12:28:38.376Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="String为啥不可变">
<meta name="twitter:description" content="经常说String不可变 String到底为啥不可变">
<meta name="twitter:image" content="https://scyx.github.io/images/String.png">



Expand Down Expand Up @@ -368,7 +370,7 @@ <h1 class="post-title" itemprop="name headline">String为啥不可变</h1>
<span class="post-meta-item-text">字数统计&#58;</span>

<span title="字数统计">
15字
288字
</span>


Expand Down Expand Up @@ -405,21 +407,20 @@ <h1 class="post-title" itemprop="name headline">String为啥不可变</h1>



<h2 id="经常说String不可变-String到底为啥不可变"><a href="#经常说String不可变-String到底为啥不可变" class="headerlink" title="经常说String不可变 String到底为啥不可变"></a>经常说String不可变 String到底为啥不可变</h2><!-- more -- >
先看看Java8中的String源码
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">final</span> <span class="class"><span class="keyword">class</span> <span class="title">String</span></span></span><br><span class="line"><span class="class"> <span class="keyword">implements</span> <span class="title">java</span>.<span class="title">io</span>.<span class="title">Serializable</span>, <span class="title">Comparable</span>&lt;<span class="title">String</span>&gt;, <span class="title">CharSequence</span> </span>&#123;</span><br><span class="line"> <span class="comment">/** The value is used for character storage. */</span></span><br><span class="line"> <span class="keyword">private</span> <span class="keyword">final</span> <span class="keyword">char</span> value[];</span><br></pre></td></tr></table></figure>
<h2 id="经常说String不可变-String到底为啥不可变"><a href="#经常说String不可变-String到底为啥不可变" class="headerlink" title="经常说String不可变 String到底为啥不可变"></a>经常说String不可变 String到底为啥不可变</h2><a id="more"></a>
<p>先看看Java8中的String源码<br><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">final</span> <span class="class"><span class="keyword">class</span> <span class="title">String</span></span></span><br><span class="line"><span class="class"> <span class="keyword">implements</span> <span class="title">java</span>.<span class="title">io</span>.<span class="title">Serializable</span>, <span class="title">Comparable</span>&lt;<span class="title">String</span>&gt;, <span class="title">CharSequence</span> </span>&#123;</span><br><span class="line"> <span class="comment">/** The value is used for character storage. */</span></span><br><span class="line"> <span class="keyword">private</span> <span class="keyword">final</span> <span class="keyword">char</span> value[];</span><br></pre></td></tr></table></figure></p>
<p>String类用final修饰,底层使用char数组value存储字符。<br>一个类用final修饰,说明它不可被继承,即没有子类可以继承String类和重写String类的方法,并且char数组用final修饰,一旦初始化,无法引用其他数组,</p>
<h2 id="而且String内部没有修改char数组的方法。因此String不可变。"><a href="#而且String内部没有修改char数组的方法。因此String不可变。" class="headerlink" title="而且String内部没有修改char数组的方法。因此String不可变。"></a>而且String内部没有修改char数组的方法。因此String不可变。</h2><h2 id="有啥好处"><a href="#有啥好处" class="headerlink" title="有啥好处"></a>有啥好处</h2><ol>
<li>String作为HashMap的key,hash值只需要计算一次。</li>
<li>字符串常量池需要<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span></span>&#123;</span><br><span class="line"> String a= <span class="string">"abc"</span>;</span><br><span class="line"> String b= <span class="string">"abc"</span>;</span><br><span class="line"> System.out.println(<span class="string">"a==b:"</span>+(a==b));<span class="comment">//true</span></span><br><span class="line"> &#125;</span><br></pre></td></tr></table></figure>
</li>
</ol>
<p><img src="/images/String.png" alt=""><br>如果一个字符串已经被创建过,那么再次创建就会从字符串常量池中取得引用,如果字符串可变,这点不能实现。</p>
<p><img src="/images/String.png" alt><br>如果一个字符串已经被创建过,那么再次创建就会从字符串常量池中取得引用,如果字符串可变,这点不能实现。</p>
<ol start="3">
<li>安全性<br>网络连接中经常使用String作为连接参数,如果可变的话,改变String的一方认为连接的是其他主机。</li>
<li>线程安全<br>String类不可变所以天生线程安全。</li>
</ol>
-->


</div>

Expand Down Expand Up @@ -607,7 +608,7 @@ <h2 id="而且String内部没有修改char数组的方法。因此String不可



<div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#经常说String不可变-String到底为啥不可变"><span class="nav-number">1.</span> <span class="nav-text">经常说String不可变 String到底为啥不可变</span></a></li></ol></div>
<div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#经常说String不可变-String到底为啥不可变"><span class="nav-number">1.</span> <span class="nav-text">经常说String不可变 String到底为啥不可变</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#而且String内部没有修改char数组的方法。因此String不可变。"><span class="nav-number">2.</span> <span class="nav-text">而且String内部没有修改char数组的方法。因此String不可变。</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#有啥好处"><span class="nav-number">3.</span> <span class="nav-text">有啥好处</span></a></li></ol></div>


</div>
Expand Down Expand Up @@ -641,7 +642,7 @@ <h2 id="而且String内部没有修改char数组的方法。因此String不可

<span class="post-meta-item-text">Site words total count&#58;</span>

<span title="Site words total count">7.5k</span>
<span title="Site words total count">7.7k</span>

</div>

Expand Down
2 changes: 1 addition & 1 deletion archives/2019/04/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ <h2 class="post-title">

<span class="post-meta-item-text">Site words total count&#58;</span>

<span title="Site words total count">7.5k</span>
<span title="Site words total count">7.7k</span>

</div>

Expand Down
2 changes: 1 addition & 1 deletion archives/2019/05/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ <h2 class="post-title">

<span class="post-meta-item-text">Site words total count&#58;</span>

<span title="Site words total count">7.5k</span>
<span title="Site words total count">7.7k</span>

</div>

Expand Down
2 changes: 1 addition & 1 deletion archives/2019/07/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ <h2 class="post-title">

<span class="post-meta-item-text">Site words total count&#58;</span>

<span title="Site words total count">7.5k</span>
<span title="Site words total count">7.7k</span>

</div>

Expand Down
2 changes: 1 addition & 1 deletion archives/2019/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ <h2 class="post-title">

<span class="post-meta-item-text">Site words total count&#58;</span>

<span title="Site words total count">7.5k</span>
<span title="Site words total count">7.7k</span>

</div>

Expand Down
2 changes: 1 addition & 1 deletion archives/2019/page/2/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ <h2 class="post-title">

<span class="post-meta-item-text">Site words total count&#58;</span>

<span title="Site words total count">7.5k</span>
<span title="Site words total count">7.7k</span>

</div>

Expand Down
2 changes: 1 addition & 1 deletion archives/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ <h2 class="post-title">

<span class="post-meta-item-text">Site words total count&#58;</span>

<span title="Site words total count">7.5k</span>
<span title="Site words total count">7.7k</span>

</div>

Expand Down
2 changes: 1 addition & 1 deletion archives/page/2/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ <h2 class="post-title">

<span class="post-meta-item-text">Site words total count&#58;</span>

<span title="Site words total count">7.5k</span>
<span title="Site words total count">7.7k</span>

</div>

Expand Down
2 changes: 1 addition & 1 deletion categories/Java/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ <h2 class="post-title">

<span class="post-meta-item-text">Site words total count&#58;</span>

<span title="Site words total count">7.5k</span>
<span title="Site words total count">7.7k</span>

</div>

Expand Down
2 changes: 1 addition & 1 deletion categories/Springboot/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ <h2 class="post-title">

<span class="post-meta-item-text">Site words total count&#58;</span>

<span title="Site words total count">7.5k</span>
<span title="Site words total count">7.7k</span>

</div>

Expand Down
2 changes: 1 addition & 1 deletion categories/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ <h1 class="post-title" itemprop="name headline">文章分类</h1>

<span class="post-meta-item-text">Site words total count&#58;</span>

<span title="Site words total count">7.5k</span>
<span title="Site words total count">7.7k</span>

</div>

Expand Down
2 changes: 1 addition & 1 deletion categories/数据库/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ <h2 class="post-title">

<span class="post-meta-item-text">Site words total count&#58;</span>

<span title="Site words total count">7.5k</span>
<span title="Site words total count">7.7k</span>

</div>

Expand Down
2 changes: 1 addition & 1 deletion css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -1823,7 +1823,7 @@ pre .javascript .function {
width: 4px;
height: 4px;
border-radius: 50%;
background: #e525ff;
background: #8e7fff;
}
.links-of-blogroll {
font-size: 13px;
Expand Down
29 changes: 10 additions & 19 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ <h1 class="post-title" itemprop="name headline">
<span class="post-meta-item-text">字数统计&#58;</span>

<span title="字数统计">
15字
288字
</span>


Expand Down Expand Up @@ -407,23 +407,14 @@ <h1 class="post-title" itemprop="name headline">




<h2 id="经常说String不可变-String到底为啥不可变"><a href="#经常说String不可变-String到底为啥不可变" class="headerlink" title="经常说String不可变 String到底为啥不可变"></a>经常说String不可变 String到底为啥不可变</h2><!-- more -- >
先看看Java8中的String源码
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">final</span> <span class="class"><span class="keyword">class</span> <span class="title">String</span></span></span><br><span class="line"><span class="class"> <span class="keyword">implements</span> <span class="title">java</span>.<span class="title">io</span>.<span class="title">Serializable</span>, <span class="title">Comparable</span>&lt;<span class="title">String</span>&gt;, <span class="title">CharSequence</span> </span>&#123;</span><br><span class="line"> <span class="comment">/** The value is used for character storage. */</span></span><br><span class="line"> <span class="keyword">private</span> <span class="keyword">final</span> <span class="keyword">char</span> value[];</span><br></pre></td></tr></table></figure>
<p>String类用final修饰,底层使用char数组value存储字符。<br>一个类用final修饰,说明它不可被继承,即没有子类可以继承String类和重写String类的方法,并且char数组用final修饰,一旦初始化,无法引用其他数组,</p>
<h2 id="而且String内部没有修改char数组的方法。因此String不可变。"><a href="#而且String内部没有修改char数组的方法。因此String不可变。" class="headerlink" title="而且String内部没有修改char数组的方法。因此String不可变。"></a>而且String内部没有修改char数组的方法。因此String不可变。</h2><h2 id="有啥好处"><a href="#有啥好处" class="headerlink" title="有啥好处"></a>有啥好处</h2><ol>
<li>String作为HashMap的key,hash值只需要计算一次。</li>
<li>字符串常量池需要<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span></span>&#123;</span><br><span class="line"> String a= <span class="string">"abc"</span>;</span><br><span class="line"> String b= <span class="string">"abc"</span>;</span><br><span class="line"> System.out.println(<span class="string">"a==b:"</span>+(a==b));<span class="comment">//true</span></span><br><span class="line"> &#125;</span><br></pre></td></tr></table></figure>
</li>
</ol>
<p><img src="/images/String.png" alt=""><br>如果一个字符串已经被创建过,那么再次创建就会从字符串常量池中取得引用,如果字符串可变,这点不能实现。</p>
<ol start="3">
<li>安全性<br>网络连接中经常使用String作为连接参数,如果可变的话,改变String的一方认为连接的是其他主机。</li>
<li>线程安全<br>String类不可变所以天生线程安全。</li>
</ol>
-->

<h2 id="经常说String不可变-String到底为啥不可变"><a href="#经常说String不可变-String到底为啥不可变" class="headerlink" title="经常说String不可变 String到底为啥不可变"></a>经常说String不可变 String到底为啥不可变</h2>
<!--noindex-->
<div class="post-button text-center">
<a class="btn" href="/2019/07/11/String为啥不可变/#more" rel="contents">
阅读全文 &raquo;
</a>
</div>
<!--/noindex-->


</div>
Expand Down Expand Up @@ -2192,7 +2183,7 @@ <h2 id="什么是插入排序"><a href="#什么是插入排序" class="headerlin

<span class="post-meta-item-text">Site words total count&#58;</span>

<span title="Site words total count">7.5k</span>
<span title="Site words total count">7.7k</span>

</div>

Expand Down
2 changes: 1 addition & 1 deletion page/2/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ <h1 id="接口"><a href="#接口" class="headerlink" title="接口"></a>接口</

<span class="post-meta-item-text">Site words total count&#58;</span>

<span title="Site words total count">7.5k</span>
<span title="Site words total count">7.7k</span>

</div>

Expand Down
Loading

0 comments on commit 0ce5f25

Please sign in to comment.