拥菢涳滊 發表於 2020-3-11 16:01:00

使用javap生成的汇编语言

<h2>1.通过javap命令查看class文件的字节码内容</h2>
<div>最简单的一个案例</div>
<div>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">class</span><span style="color: rgba(0, 0, 0, 1)"> Test {
    </span><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">static</span> <span style="color: rgba(0, 0, 255, 1)">void</span><span style="color: rgba(0, 0, 0, 1)"> main(String[] args) {
      </span><span style="color: rgba(0, 0, 255, 1)">int</span> a = 2<span style="color: rgba(0, 0, 0, 1)">;
      </span><span style="color: rgba(0, 0, 255, 1)">int</span> b = 5<span style="color: rgba(0, 0, 0, 1)">;
      </span><span style="color: rgba(0, 0, 255, 1)">int</span> c = b-<span style="color: rgba(0, 0, 0, 1)">a;
      System.out.println(c);
    }
}</span></pre>
</div>
<p>先使用javac命令进行编译,Test.class,再使用</p>
<div>
<div class="cnblogs_code">
<pre>javap ‐v Test1.<span style="color: rgba(0, 0, 255, 1)">class</span> &gt; Test.txt</pre>
</div>
<p>Test.txt内容如下</p>
<div>内容大致分为4个部分:</div>
<ol>
<li>第一部分:显示了生成这个class的java源文件、版本信息、生成时间等。</li>
<li>第二部分:显示了该类中所涉及到常量池,共26个常量。</li>
<li>第三部分:显示该类的构造器,编译器自动插入的。</li>
<li>第四部分:显示了main方的信息。(这个是需要我们重点关注的)</li>
</ol>
<div class="cnblogs_code">
<pre>Classfile /E:/Astudy/JVM/Test.<span style="color: rgba(0, 0, 255, 1)">class</span><span style="color: rgba(0, 0, 0, 1)">
Last modified </span>2020-3-8; size 398<span style="color: rgba(0, 0, 0, 1)"> bytes
MD5 checksum a638d93d1191aa144f8140f0fcfcd644
Compiled from </span>"Test.java"
<span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">class</span><span style="color: rgba(0, 0, 0, 1)"> Test
minor version: </span>0<span style="color: rgba(0, 0, 0, 1)">
major version: </span>52<span style="color: rgba(0, 0, 0, 1)">
flags: ACC_PUBLIC, ACC_SUPER
Constant pool:    </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">常量池</span>
   #1 = Methodref <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">方法引用          #5.#14         </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> java/lang/Object."&lt;init&gt;":()V</span>
   #2 = Fieldref<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">字段引用         #15.#16      </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> java/lang/System.out:Ljava/io/PrintStream;</span>
   #3 = Methodref          #17.#18      <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> java/io/PrintStream.println:(I)V</span>
   #4 = Class   <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">类         #19            </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> Test</span>
   #5 = Class   <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">UTF-8编码的字符串         #20            </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> java/lang/Object</span>
   #6 = Utf8               &lt;init&gt;<span style="color: rgba(0, 0, 0, 1)">
   #</span>7 =<span style="color: rgba(0, 0, 0, 1)"> Utf8               ()V
   #</span>8 =<span style="color: rgba(0, 0, 0, 1)"> Utf8               Code
   #</span>9 =<span style="color: rgba(0, 0, 0, 1)"> Utf8               LineNumberTable
#</span>10 =<span style="color: rgba(0, 0, 0, 1)"> Utf8               main
#</span>11 = Utf8               ([Ljava/lang/<span style="color: rgba(0, 0, 0, 1)">String;)V
#</span>12 =<span style="color: rgba(0, 0, 0, 1)"> Utf8               SourceFile
#</span>13 =<span style="color: rgba(0, 0, 0, 1)"> Utf8               Test.java
#</span>14 = NameAndType<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">字段或方法的符号引用      #6:#7          </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> "&lt;init&gt;":()V</span>
#15 = Class            #21            <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> java/lang/System</span>
#16 = NameAndType      #22:#23      <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> out:Ljava/io/PrintStream;</span>
#17 = Class            #24            <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> java/io/PrintStream</span>
#18 = NameAndType      #25:#26      <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> println:(I)V</span>
#19 =<span style="color: rgba(0, 0, 0, 1)"> Utf8               Test
#</span>20 = Utf8               java/lang/<span style="color: rgba(0, 0, 0, 1)">Object
#</span>21 = Utf8               java/lang/<span style="color: rgba(0, 0, 0, 1)">System
#</span>22 =<span style="color: rgba(0, 0, 0, 1)"> Utf8               out
#</span>23 = Utf8               Ljava/io/<span style="color: rgba(0, 0, 0, 1)">PrintStream;
#</span>24 = Utf8               java/io/<span style="color: rgba(0, 0, 0, 1)">PrintStream
#</span>25 =<span style="color: rgba(0, 0, 0, 1)"> Utf8               println
#</span>26 =<span style="color: rgba(0, 0, 0, 1)"> Utf8               (I)V
{
</span><span style="color: rgba(0, 0, 255, 1)">public</span> Test();   <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">无参构造</span>
    descriptor: ()V <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">返回值类型</span>
    flags: ACC_PUBLIC    <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">访问修饰符</span>
<span style="color: rgba(0, 0, 0, 1)">    Code:
    </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">依次为,栈的大小,局部变量表的大小,参数的个数</span>
      stack=1, locals=1, args_size=1
         0<span style="color: rgba(0, 0, 0, 1)">: aload_0
         </span>1: invokespecial #1                  <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> Method java/lang/Object."&lt;init&gt;":()V</span>
         4: <span style="color: rgba(0, 0, 255, 1)">return</span><span style="color: rgba(0, 0, 0, 1)">
      LineNumberTable:
      line </span>1: 0

<span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">static</span> <span style="color: rgba(0, 0, 255, 1)">void</span><span style="color: rgba(0, 0, 0, 1)"> main(java.lang.String[]);
    descriptor: ([Ljava</span>/lang/<span style="color: rgba(0, 0, 0, 1)">String;)V
    flags: ACC_PUBLIC, ACC_STATIC
    Code:
      stack</span>=2, locals=4, args_size=1
         0: iconst_2                <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">将int类型的2压入栈      </span>
         1: istore_1                <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">出栈一个变量放入局部变量表中下标为1的位置,下标为0的位置存放的是this指针,此时栈为空,</span>
         2: iconst_5                <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">将int类型的5压入栈</span>
         3: istore_2                <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">出栈一个变量放入局部变量表中下标为2的位置,下标为0的位置存放的是this指针,此时栈为空,</span>
         4: iload_2                  <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">从局部变量表中取出下标为2(实际值此处为5)的变量压入操作数栈中</span>
         5: iload_1                  <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">从局部变量表中取出下标为1(实际值此处为2)的变量压入操作数栈中</span>
         6: isub                  <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">在操作数栈中做减操作,结果为3</span>
         7: istore_3                <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">出栈一个变量放入局部变量表中下标为3的位置,下标为0的位置存放的是this指针,此时栈为空,</span>
         8: getstatic   #2      <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">去常量池中引用"#2"符号引用的类与方法          </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> Field java/lang/System.out:Ljava/io/PrintStream;</span>
      11: iload_3                  <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">从局部变量表中取出下标为3(实际值此处为3)的变量压入操作数栈中</span>
      12: invokevirtual #3      <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">调度对象的实现方法          </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> Method java/io/PrintStream.println:(I)V</span>
      15: <span style="color: rgba(0, 0, 255, 1)">return</span><span style="color: rgba(0, 0, 0, 1)">
      LineNumberTable:
      line </span>3: 0<span style="color: rgba(0, 0, 0, 1)">
      line </span>4: 2<span style="color: rgba(0, 0, 0, 1)">
      line </span>5: 4<span style="color: rgba(0, 0, 0, 1)">
      line </span>6: 8<span style="color: rgba(0, 0, 0, 1)">
      line </span>7: 15<span style="color: rgba(0, 0, 0, 1)">
}
SourceFile: </span>"Test.java"</pre>
</div>
<h3>常量池</h3>
<div>  Constant               TypeValue      说明</div>
<ul>
<li>CONSTANT_Class          7        类或接口的符号引用</li>
<li>CONSTANT_Fieldref    &nbsp; &nbsp;&nbsp;    9        字段的符号引用</li>
<li>CONSTANT_Methodref       &nbsp; &nbsp;10        类中方法的符号引用</li>
<li>CONSTANT_InterfaceMethodref&nbsp;   &nbsp; &nbsp;11        接口中方法的符号引用</li>
<li>CONSTANT_String          8        字符串类型常量</li>
<li>CONSTANT_Integer         &nbsp; 3        整形常量</li>
<li>CONSTANT_Float          &nbsp; 4        浮点型常量</li>
<li>CONSTANT_Long          &nbsp;&nbsp;5        长整型常量</li>
<li>CONSTANT_Double         &nbsp; 6        双精度浮点型常量</li>
<li>CONSTANT_NameAndType      12        字段或方法的符号引用</li>
<li>CONSTANT_Utf8&nbsp;           1&nbsp;        UTF-8编码的字符串</li>
<li>CONSTANT_MethodHandle      15        表示方法句柄</li>
<li>CONSTANT_MethodType       16        标志方法类型</li>
<li>CONSTANT_InvokeDynamic     &nbsp; 18        表示一个动态方法调用点</li>
</ul>
<div>官方文档</div>
<div>图示:你们一定没见过画的这么丑的图</div>
<div><img src="https://img2020.cnblogs.com/i-beta/1397021/202003/1397021-20200311143934739-1944572645.png">
<p>&nbsp;</p>
<h2>&nbsp;二:i++和++i的区别</h2>
</div>
<div>java代码</div>
<div>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">class</span><span style="color: rgba(0, 0, 0, 1)"> Test2 {
    </span><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">static</span> <span style="color: rgba(0, 0, 255, 1)">void</span><span style="color: rgba(0, 0, 0, 1)"> main(String[] args) {
      </span><span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> Test2().method1();
      </span><span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> Test2().method2();
    }

    </span><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">void</span><span style="color: rgba(0, 0, 0, 1)"> method1() {
         </span><span style="color: rgba(0, 0, 255, 1)">int</span> i = 1<span style="color: rgba(0, 0, 0, 1)">;
      </span><span style="color: rgba(0, 0, 255, 1)">int</span> a = i++<span style="color: rgba(0, 0, 0, 1)">;
      System.out.println(a);
      </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">打印1</span>
<span style="color: rgba(0, 0, 0, 1)">    }

    </span><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">void</span><span style="color: rgba(0, 0, 0, 1)"> method2() {
      </span><span style="color: rgba(0, 0, 255, 1)">int</span> i = 1<span style="color: rgba(0, 0, 0, 1)">;
      </span><span style="color: rgba(0, 0, 255, 1)">int</span> a = ++<span style="color: rgba(0, 0, 0, 1)">i;
      System.out.println(a);
      </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">打印2 </span>
<span style="color: rgba(0, 0, 0, 1)">    }
}</span></pre>
</div>
<p>执行javac之后执行javap</p>
<p>字节码节选</p>
<p>i++</p>
<div class="cnblogs_code">
<pre>    stack=2, locals=3, args_size=1
         0: iconst_1            <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">将int类型的1压入栈</span>
         1: istore_1            <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">出栈一个变量放入局部变量表中下标为1的位置,下标为0的位置存放的是this指针,此时栈为空,    </span>
         2: iload_1                <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">从局部变量表中取出下标为1(实际值此处为1)的变量压入操作数栈中</span>
         3: iinc          1, 1    <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">将局部变量表中下标为1的变量进行加1操作</span>
         6: istore_2            <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">出栈一个变量放入局部变量表中下标为2的位置,这一步没有对操作栈中的数进行操作,直接出栈到变量表中</span>
         7: getstatic   #6       <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">去常量池中引用"#6"符号引用的类与方法               </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> Field java/lang/System.out:Ljava/io/PrintStream;</span>
      10: iload_2                <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">从局部变量表中取出下标为2(实际值此处为1)的变量压入操作数栈中</span>
      11: invokevirtual #7       <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">执行println方法               </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> Method java/io/PrintStream.println:(I)V</span>
      14: <span style="color: rgba(0, 0, 255, 1)">return</span></pre>
</div>
<p>++i</p>
<div class="cnblogs_code">
<pre>      stack=2, locals=3, args_size=1
         0: iconst_1            <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">将int类型的1压入栈</span>
         1: istore_1            <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">出栈一个变量放入局部变量表中下标为1的位置,下标为0的位置存放的是this指针,此时栈为空,    </span>
         2: iinc          1, 1    <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">将局部变量表中下标为1的变量进行加1操作</span>
         5: iload_1                <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">从局部变量表中取出下标为1(实际值此处为2)的变量压入操作数栈中</span>
         6: istore_2            <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">出栈一个变量放入局部变量表中下标为2的位置,(实际值此处为2)</span>
         7: getstatic   #6    <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">去常量池中引用"#6"符号引用的类与方法               </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> Field java/lang/System.out:Ljava/io/PrintStream;</span>
      10: iload_2                <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">从局部变量表中取出下标为2(实际值此处为2)的变量压入操作数栈中</span>
      11: invokevirtual #7    <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">执行println方法               </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> Method java/io/PrintStream.println:(I)V</span>
      14: <span style="color: rgba(0, 0, 255, 1)">return</span></pre>
</div>
<div>区别:</div>
<div>i++</div>
<ul>
<li>只是在本地变量中对数字做了相加,并没有将数据压入到操作栈</li>
<li>将前面拿到的数字1,再次从操作栈中拿到,压入到本地变量中</li>
</ul>
<div>++i</div>
<ul>
<li>将本地变量中的数字做了相加,并且将数据压入到操作栈</li>
<li>将操作栈中的数据,再次压入到本地变量中&nbsp;</li>
</ul>
<h2>三:字符串拼接</h2>
<p>使用StringBuilder和"+"号拼接哪个效率高?</p>
</div>
<div>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">class</span><span style="color: rgba(0, 0, 0, 1)"> Test3 {
</span><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">static</span> <span style="color: rgba(0, 0, 255, 1)">void</span><span style="color: rgba(0, 0, 0, 1)"> main(String[] args) {
      </span><span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> Test3().m1();
      </span><span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> Test3().m2();
      }

</span><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">void</span><span style="color: rgba(0, 0, 0, 1)"> m1() {
      String s1 </span>= "123"<span style="color: rgba(0, 0, 0, 1)">;
      String s2 </span>= "456"<span style="color: rgba(0, 0, 0, 1)">;
      String s3 </span>= s1 +<span style="color: rgba(0, 0, 0, 1)"> s2;
      System.out.println(s3);
      }

</span><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">void</span><span style="color: rgba(0, 0, 0, 1)"> m2() {
      String s1 </span>= "123"<span style="color: rgba(0, 0, 0, 1)">;
      String s2 </span>= "456"<span style="color: rgba(0, 0, 0, 1)">;
      StringBuilder sb </span>= <span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> StringBuilder();
      sb.append(s1);
      sb.append(s2);
      String s3 </span>=<span style="color: rgba(0, 0, 0, 1)"> sb.toString();
      System.out.println(s3);
      }
      }</span></pre>
</div>
<p>直接上字节码</p>
<p>字符串在类加载的时候会保存至常量池当中</p>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 0, 0, 1)">Constant pool:
   #</span>1 = Methodref          #14.#25      <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> java/lang/Object."&lt;init&gt;":()V</span>
   #2 = Class            #26            <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> Test3</span>
   #3 = Methodref          #2.#25         <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> Test3."&lt;init&gt;":()V</span>
   #4 = Methodref          #2.#27         <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> Test3.m1:()V</span>
   #5 = Methodref          #2.#28         <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> Test3.m2:()V</span>
   #6 = String             #29            <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> 123</span>
   #7 = String             #30            <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> 456</span>
   #8 = Class            #31            <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> java/lang/StringBuilder</span>
   #9 = Methodref          #8.#25         <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> java/lang/StringBuilder."&lt;init&gt;":()V</span>
#10 = Methodref          #8.#32         <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;</span>
#11 = Methodref          #8.#33         <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> java/lang/StringBuilder.toString:()Ljava/lang/String;</span>
#12 = Fieldref         #34.#35      <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> java/lang/System.out:Ljava/io/PrintStream;</span>
#13 = Methodref          #36.#37      <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> java/io/PrintStream.println:(Ljava/lang/String;)V</span>
#14 = Class            #38            <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> java/lang/Object</span>
#15 = Utf8               &lt;init&gt;<span style="color: rgba(0, 0, 0, 1)">
#</span>16 =<span style="color: rgba(0, 0, 0, 1)"> Utf8               ()V
#</span>17 =<span style="color: rgba(0, 0, 0, 1)"> Utf8               Code
#</span>18 =<span style="color: rgba(0, 0, 0, 1)"> Utf8               LineNumberTable
#</span>19 =<span style="color: rgba(0, 0, 0, 1)"> Utf8               main
#</span>20 = Utf8               ([Ljava/lang/<span style="color: rgba(0, 0, 0, 1)">String;)V
#</span>21 =<span style="color: rgba(0, 0, 0, 1)"> Utf8               m1
#</span>22 =<span style="color: rgba(0, 0, 0, 1)"> Utf8               m2
#</span>23 =<span style="color: rgba(0, 0, 0, 1)"> Utf8               SourceFile
#</span>24 =<span style="color: rgba(0, 0, 0, 1)"> Utf8               Test3.java
#</span>25 = NameAndType      #15:#16      <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> "&lt;init&gt;":()V</span>
#26 =<span style="color: rgba(0, 0, 0, 1)"> Utf8               Test3
#</span>27 = NameAndType      #21:#16      <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> m1:()V</span>
#28 = NameAndType      #22:#16      <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> m2:()V</span>
#29 = Utf8               123<span style="color: rgba(0, 0, 0, 1)">
#</span>30 = Utf8               456<span style="color: rgba(0, 0, 0, 1)">
#</span>31 = Utf8               java/lang/<span style="color: rgba(0, 0, 0, 1)">StringBuilder
#</span>32 = NameAndType      #39:#40      <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> append:(Ljava/lang/String;)Ljava/lang/StringBuilder;</span>
#33 = NameAndType      #41:#42      <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> toString:()Ljava/lang/String;</span>
#34 = Class            #43            <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> java/lang/System</span>
#35 = NameAndType      #44:#45      <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> out:Ljava/io/PrintStream;</span>
#36 = Class            #46            <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> java/io/PrintStream</span>
#37 = NameAndType      #47:#48      <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> println:(Ljava/lang/String;)V</span>
#38 = Utf8               java/lang/<span style="color: rgba(0, 0, 0, 1)">Object
#</span>39 =<span style="color: rgba(0, 0, 0, 1)"> Utf8               append
#</span>40 = Utf8               (Ljava/lang/String;)Ljava/lang/<span style="color: rgba(0, 0, 0, 1)">StringBuilder;
#</span>41 =<span style="color: rgba(0, 0, 0, 1)"> Utf8               toString
#</span>42 = Utf8               ()Ljava/lang/<span style="color: rgba(0, 0, 0, 1)">String;
#</span>43 = Utf8               java/lang/<span style="color: rgba(0, 0, 0, 1)">System
#</span>44 =<span style="color: rgba(0, 0, 0, 1)"> Utf8               out
#</span>45 = Utf8               Ljava/io/<span style="color: rgba(0, 0, 0, 1)">PrintStream;
#</span>46 = Utf8               java/io/<span style="color: rgba(0, 0, 0, 1)">PrintStream
#</span>47 =<span style="color: rgba(0, 0, 0, 1)"> Utf8               println
#</span>48 = Utf8               (Ljava/lang/String;)V</pre>
</div>
<p>"+"号拼接</p>
</div>
<div>
<div class="cnblogs_code">
<pre> stack=2, locals=4, args_size=1
         0: ldc         #6       <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">将常量池中的"123"压入栈                     </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> String 123</span>
         2: astore_1            <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">将引用类型(String)的值存入局部变量表中的下标为1的位置,下标为0的位置为this</span>
         3: ldc         #7    <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">将常量池中的"456"压入栈                        </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> String 456</span>
         5: astore_2            <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">将引用类型(String)的值存入局部变量表中的下标为2的位置</span>
         6: <span style="color: rgba(0, 0, 255, 1)">new</span>         #8    <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">创建一个新的StringBuilder对象               </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> class java/lang/StringBuilder</span>
         9: dup                  <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">复制栈顶部一个字长内容</span>
      10: invokespecial #9    <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">根据编译时类型来调用实例方法                     </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> Method java/lang/StringBuilder."&lt;init&gt;":()V</span>
      13: aload_1                <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">从局部变量表中取出下标为1的变量(此处为"123")放入到操作数栈中      </span>
      14: invokevirtual #10   <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">调用StringBuilder的append()方法                  </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;</span>
      17: aload_2                <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">从局部变量表中取出下标为1的变量(此处为"465")放入到操作数栈中</span>
      18: invokevirtual #10   <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">调用StringBuilder的append()方法               </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;</span>
      21: invokevirtual #11   <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">调用StringBuilder的toString()方法             </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> Method java/lang/StringBuilder.toString:()Ljava/lang/String;</span>
      24: astore_3            <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">将引用类型(String)的值存入局部变量表中的下标为3的位置</span>
      25: getstatic   #12   <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">获取静态字段System.out            </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> Field java/lang/System.out:Ljava/io/PrintStream;</span>
      28: aload_3                <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">从局部变量表中取出下标为3的变量(此处为"123456")放入到操作数栈中</span>
      29: invokevirtual #13   <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">调用System.out 的println()方法            </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> Method java/io/PrintStream.println:(Ljava/lang/String;)V</span>
      32: <span style="color: rgba(0, 0, 255, 1)">return</span></pre>
</div>
<p>StringBuilder&nbsp;</p>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 0, 0, 1)"> Code:
      stack</span>=2, locals=5, args_size=1
         0: ldc         #6       <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">将常量池中的"123"压入栈                     </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> String 123</span>
         2: astore_1            <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">将引用类型(String)的值存入局部变量表中的下标为1的位置,下标为0的位置为this</span>
         3: ldc         #7    <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">将常量池中的"456"压入栈                        </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> String 456</span>
         5: astore_2            <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">将引用类型(String)的值存入局部变量表中的下标为2的位置</span>
         6: <span style="color: rgba(0, 0, 255, 1)">new</span>         #8    <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">创建一个新的StringBuilder对象               </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> class java/lang/StringBuilder</span>
         9: dup                  <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">复制栈顶部一个字长内容</span>
      10: invokespecial #9    <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">根据编译时类型来调用实例方法                     </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> Method java/lang/StringBuilder."&lt;init&gt;":()V</span>
      13: astore_3            <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">将引用类型(String)的值存入局部变量表中的下标为3的位置</span>
      14: aload_3                <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">从局部变量表中取出下标为3的变量放入到操作数栈中</span>
      15: aload_1                <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">从局部变量表中取出下标为1的变量(此处为"123")放入到操作数栈中      </span>
      16: invokevirtual #10   <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">调用StringBuilder的append()方法               </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;</span>
      19: pop                  <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">弹出栈顶端一个字长的内容</span>
      20: aload_3                <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">从局部变量表中取出下标为3的变量放入到操作数栈中</span>
      21: aload_2                <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">从局部变量表中取出下标为2的变量放入到操作数栈中</span>
      22: invokevirtual #10   <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">调用StringBuilder的append()方法                  </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;</span>
      25: pop                  <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">弹出栈顶端一个字长的内容</span>
      26: aload_3                <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">从局部变量表中取出下标为3的变量放入到操作数栈中</span>
      27: invokevirtual #11   <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">调用StringBuilder的toString()方法                </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> Method java/lang/StringBuilder.toString:()Ljava/lang/String;</span>
      30: astore      4      <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">将引用类型或returnAddress类型值存入局部变量下标为4</span>
      32: getstatic   #12    <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">获取静态字段System.out               </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> Field java/lang/System.out:Ljava/io/PrintStream;</span>
      35: aload         4      <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">从局部变量表中取出下标为4的变量(此处为"123456")放入到操作数栈中</span>
      37: invokevirtual #13    <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">调用System.out 的println()方法            </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> Method java/io/PrintStream.println:(Ljava/lang/String;)V</span>
      40: <span style="color: rgba(0, 0, 255, 1)">return</span></pre>
</div>
<p>从通过字节码的方式我们可以看出,+号其实还是使用了StringBuilder对象的append方法,所以他们的效率是一样的。但是真的是这样吗?如果是循环拼接呢?</p>
<h2>循环拼接</h2>
<p>使用+拼接</p>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 0, 0, 1)"> Code:
      stack</span>=2, locals=3, args_size=1
         0: ldc         #6             <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">去常量池中找字符串,结果为空   </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> String</span>
         2: astore_1                     <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">将引用类型(String)的值存入局部变量表中的下标为1的位置,下标为0的位置为this</span>
         3: iconst_0                     <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">将int类型的0压入栈</span>
         4: istore_2                     <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">将int类型的0弹出栈,存入局部变量表中下标为2的位置    </span>
         5: iload_2                         <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">将局部变量表中下标为2的值压入栈中</span>
         6: iconst_5                     <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">将int类型的5压入栈    </span>
         7: if_icmpge   35             <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">将操作数栈中的两个数进行比较,如果一个int(第一次循环值0)类型值大于或者等于另外一个int(值为5)类型值,则跳转35处执行    </span>
      10: <span style="color: rgba(0, 0, 255, 1)">new</span>         #7             <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">创建一个StringBuilder对象          </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> class java/lang/StringBuilder</span>
      13: dup                           <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">复制栈顶部一个字长内容    </span>
      14: invokespecial #8                        <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> Method java/lang/StringBuilder."&lt;init&gt;":()V</span>
      17: aload_1                        <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">从局部变量表中取出下标为1的String变量压入操作数栈中</span>
      18: invokevirtual #9                        <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;</span>
      21: iload_2                        <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">从局部变量表中取出下标为2的int类型变量压入操作数栈中</span>
      22: invokevirtual #10         <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">调用append方法      </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;</span>
      25: invokevirtual #11         <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">调用toString方法      </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> Method java/lang/StringBuilder.toString:()Ljava/lang/String;</span>
      28: astore_1                  <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">将引用类型(String)的值存入局部变量表中的下标为1的位置,下标为0的位置为this    </span>
      29: iinc          2, 1            <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">将局部变量表中下标为2的值加1</span>
      32: <span style="color: rgba(0, 0, 255, 1)">goto</span>          5             <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">跳转到5</span>
      35: getstatic   #12         <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">获取System.out      </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> Field java/lang/System.out:Ljava/io/PrintStream;</span>
      38: aload_1                        <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">从局部变量表中取出下标为1的String变量压入操作数栈中</span>
      39: invokevirtual #13         <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">调用println方法      </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> Method java/io/PrintStream.println:(Ljava/lang/String;)V</span>
      42: <span style="color: rgba(0, 0, 255, 1)">return</span></pre>
</div>
<p>使用StringBuilder</p>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 0, 0, 1)"> flags: ACC_PUBLIC
    Code:
      stack</span>=2, locals=3, args_size=1
         0: <span style="color: rgba(0, 0, 255, 1)">new</span>         #7            <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">创建一个StringBuilder对象      </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> class java/lang/StringBuilder</span>
         3: dup                            <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">复制栈顶部一个字长内容</span>
         4: invokespecial #8                  <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> Method java/lang/StringBuilder."&lt;init&gt;":()V</span>
         7: astore_1                  <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">将引用类型(String)的值存入局部变量表中的下标为1的位置,下标为0的位置为this</span>
         8: iconst_0                  <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">将int类型的0压入栈</span>
         9: istore_2                  <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">将int类型的0弹出栈,存入局部变量表中下标为2的位置    </span>
      10: iload_2                        <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">将局部变量表中下标为2的值压入栈中</span>
      11: iconst_5                  <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">将int类型的5压入栈    </span>
      12: if_icmpge   27            <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">将操作数栈中的两个数进行比较,如果一个int(第一次循环值0)类型值大于或者等于另外一个int(值为5)类型值,则跳转27处执行</span>
      15: aload_1                        <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">从局部变量表中取出下标为1的String变量压入操作数栈中</span>
      16: iload_2                        <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">从局部变量表中取出下标为2的int类型变量压入操作数栈中</span>
      17: invokevirtual #10         <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">调用append方法         </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;</span>
      20: pop                            <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">弹出栈顶端一个字长的内容</span>
      21: iinc          2, 1            <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">将局部变量表中下标为2的值加1</span>
      24: <span style="color: rgba(0, 0, 255, 1)">goto</span>          10            <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">跳转到10</span>
      27: getstatic   #12         <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">获取System.ou      </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> Field java/lang/System.out:Ljava/io/PrintStream;</span>
      30: aload_1                        <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">从局部变量表中取出下标为1的String变量压入操作数栈中</span>
      31: invokevirtual #11         <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">调用toString方法      </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> Method java/lang/StringBuilder.toString:()Ljava/lang/String;</span>
      34: invokevirtual #13         <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">调用println方法      </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> Method java/io/PrintStream.println:(Ljava/lang/String;)V</span>
      37: <span style="color: rgba(0, 0, 255, 1)">return</span></pre>
</div>
<p>结论,使用+号每一次循环都会创建一个StringBuilder对象每次拼接完之后都会调用toString()方法,这样的话效率肯定没有直接用StringBuildr效率高,因为StringBuildr只创建了一个对象,调用了一次toString()方法</p>
<h2>代码优化建议</h2>
<h3>1、尽可能使用局部变量</h3>
<div><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">  调用方法时传递的参数以及在调用中创建的临时变量都保存在栈中速度较快,其他变</span><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">量,如静态变量、实例变量等,都在堆中创建,速度较慢。另外,栈中创建的变量,随</span><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">着方法的运行结束,这些内容就没了,不需要额外的垃圾回收。</span></div>
<h3><span style="color: rgba(51, 51, 51, 1); font-family: 宋体"><span style="font-size: 17.0836px">2、尽量减少对变量的重复计算</span></span></h3>
<div><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">明确一个概念,对方法的调用,即使方法中只有一句语句,也是有消耗的。所以例如下</span><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">面的操作</span></div>
<div>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 0, 255, 1)">for</span> (<span style="color: rgba(0, 0, 255, 1)">int</span> i = 0; i &lt; list.size(); i++) {...}</pre>
</div>
<div><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: 宋体; color: rgba(51, 51, 51, 1)"><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">建议替换为:</span></span>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 0, 255, 1)">int</span> length = list.size(); <span style="color: rgba(0, 0, 255, 1)">for</span> (<span style="color: rgba(0, 0, 255, 1)">int</span> i = 0, i &lt; length; i++) {...}</pre>
</div>
<h3>3、尽量采用懒加载的策略,即在需要的时候才创建</h3>
<div class="cnblogs_code">
<pre>String str = "aaa"; <span style="color: rgba(0, 0, 255, 1)">if</span> (i == 1){ list.add(str); }<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">建议替换成 if (i == 1){ String str = "aaa"; list.add(str); }</span></pre>
</div>
<h3>4、异常不应该用来控制程序流程</h3>
<div><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">  异常对性能不利。抛出异常首先要创建一个新的对象,</span><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: Open Sans; color: rgba(51, 51, 51, 1)">Throwable</span><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">接口的构造函数调用</span><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">名为</span><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: Open Sans; color: rgba(51, 51, 51, 1)">fillInStackTrace()</span><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">的本地同步方 法,</span><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: Open Sans; color: rgba(51, 51, 51, 1)">fillInStackTrace()</span><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">方法检查堆栈,收集调用跟踪</span><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">信息。只要有异常被抛出,</span><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: Open Sans; color: rgba(51, 51, 51, 1)">Java</span><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">虚拟机就必须调整调用堆栈,因为在处理过程中创建 了</span><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">一个新的对象。异常只能用于错误处理,不应该用来控制程序流程。</span></div>
<h3><span style="color: rgba(51, 51, 51, 1); font-family: 宋体"><span style="font-size: 17.0836px">5、不要将数组声明为public static final</span></span></h3>
<div><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">因为这毫无意义,这样只是定义了引用为</span><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: Open Sans; color: rgba(51, 51, 51, 1)">static final</span><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">,数组的内容还是可以随意改变的,</span><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">将数组声明为</span><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: Open Sans; color: rgba(51, 51, 51, 1)">public</span><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">更是一个安全漏洞,这意味着这个数组可以被外部类所改变。</span></div>
<h3><span style="color: rgba(51, 51, 51, 1); font-family: 宋体"><span style="font-size: 17.0836px">6、不要创建一些不使用的对象,不要导入一些不使用的类</span></span></h3>
<div><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">如果代码中出现</span><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: Open Sans; color: rgba(51, 51, 51, 1)">"The value of the local variable i is not used"</span><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">、</span><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: Open Sans; color: rgba(51, 51, 51, 1)">"The</span><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: Open Sans; color: rgba(51, 51, 51, 1)">import java.util is never used"</span><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">,那么请删除这些无用的内容</span></div>
<h3><span style="color: rgba(51, 51, 51, 1); font-family: 宋体"><span style="font-size: 17.0836px">7、程序运行过程中避免使用反射</span></span></h3>
<p>  <span style="font-size: 12.8127pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">反射是</span><span style="font-size: 12.8127pt; font-family: &quot;Open Sans&quot;; color: rgba(51, 51, 51, 1)">Java</span><span style="font-size: 12.8127pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">提供给用户一个很强大的功能,功能强大往往意味着效率不高。不建议在程序</span><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">运行过程中使用尤其是频繁使用反射机制,特别是 </span><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: Open Sans; color: rgba(51, 51, 51, 1)">Method</span><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">的</span><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: Open Sans; color: rgba(51, 51, 51, 1)">invoke</span><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">方法。</span></p>
<div><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">如果确实有必要,一种建议性的做法是将那些需要通过反射加载的类在项目启动的时候</span><span style="color: rgba(51, 51, 51, 1); font-family: 宋体"><span style="font-size: 12.8127pt">通过反射实例化出一个对象并放入内存。</span></span></div>
<h3><span style="color: rgba(51, 51, 51, 1); font-family: 宋体"><span style="color: rgba(51, 51, 51, 1); font-family: 宋体"><span style="font-size: 17.0836px">8、使用数据库连接池和线程池</span></span><span style="color: rgba(51, 51, 51, 1); font-family: 宋体; font-size: 17.0836px">  </span></span></h3>
<div><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">  这两个池都是用于重用对象的,前者可以避免频繁地打开和关闭连接,后者可以避免频</span><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">繁地创建和销毁线程</span></div>
<h3><span style="color: rgba(51, 51, 51, 1); font-family: 宋体"><span style="color: rgba(51, 51, 51, 1); font-family: 宋体">9、容器初始化时尽可能指定长度</span></span></h3>
<p><span style="color: rgba(51, 51, 51, 1); font-family: 宋体"><span style="color: rgba(51, 51, 51, 1); font-family: 宋体">  </span></span><span style="font-size: 12.8127pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">容器初始化时尽可能指定长度,如:</span><span style="font-size: 12.8127pt; font-family: &quot;Open Sans&quot;; color: rgba(51, 51, 51, 1)">new ArrayList&lt;&gt;(10); new HashMap&lt;&gt;(32); </span><span style="font-size: 12.8127pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">避免容</span><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">器长度不足时,扩容带来的性能损耗。</span></p>
<h3><span style="color: rgba(51, 51, 51, 1); font-family: 宋体"><span style="color: rgba(51, 51, 51, 1); font-family: 宋体">10、ArrayList随机遍历快,LinkedList添加删除快</span></span></h3>
<h3>&nbsp;</h3>
<h3><span style="color: rgba(51, 51, 51, 1); font-family: 宋体"><span style="color: rgba(51, 51, 51, 1); font-family: 宋体">11、使用Entry遍历Map</span></span></h3>
<div class="cnblogs_code">
<pre>Map&lt;String,String&gt; map = <span style="color: rgba(0, 0, 255, 1)">new</span> HashMap&lt;&gt;<span style="color: rgba(0, 0, 0, 1)">();
</span><span style="color: rgba(0, 0, 255, 1)">for</span> (Map.Entry&lt;String,String&gt;<span style="color: rgba(0, 0, 0, 1)"> entry : map.entrySet()) {
String key </span>=<span style="color: rgba(0, 0, 0, 1)"> entry.getKey();
String value </span>=<span style="color: rgba(0, 0, 0, 1)"> entry.getValue();
}</span></pre>
</div>
<h3><span style="color: rgba(51, 51, 51, 1); font-family: 宋体"><span style="color: rgba(51, 51, 51, 1); font-family: 宋体">12、不要手动调用System.gc();</span></span></h3>
<h3><span style="color: rgba(51, 51, 51, 1); font-family: 宋体"><span style="color: rgba(51, 51, 51, 1); font-family: 宋体">13、String尽量少用正则表达式</span></span></h3>
<div><span style="font-size: 12.8125pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">正则表达式虽然功能强大,但是其效率较低,除非是有需要,否则尽可能少用。</span></div>
<div><span style="font-size: 12.8125pt; font-family: &quot;Open Sans&quot;; color: rgba(51, 51, 51, 1)">replace()&nbsp;</span><span style="font-size: 12.8125pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">不支持正则</span></div>
<div><span style="font-size: 12.8125pt; font-family: &quot;Open Sans&quot;; color: rgba(51, 51, 51, 1)">replaceAll()&nbsp;</span><span style="font-size: 12.8125pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">支持正则</span></div>
<div><span style="font-size: 12.8125pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">如果仅仅是字符的替换建议使用</span><span style="font-size: 12.8125pt; font-family: &quot;Open Sans&quot;; color: rgba(51, 51, 51, 1)">replace()</span></div>
<h3>14、日志的输出要注意级别</h3>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> 当前的日志级别是error</span>
LOGGER.info("保存出错!" + user);</pre>
</div>
<h3>15、对资源的close()建议分开操作</h3>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 0, 255, 1)">try</span><span style="color: rgba(0, 0, 0, 1)">{
    XXX.close();
    YYY.close();
}</span><span style="color: rgba(0, 0, 255, 1)">catch</span><span style="color: rgba(0, 0, 0, 1)"> (Exception e){
...
}
</span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> 建议改为</span>
<span style="color: rgba(0, 0, 255, 1)">try</span><span style="color: rgba(0, 0, 0, 1)">{
    XXX.close();
}</span><span style="color: rgba(0, 0, 255, 1)">catch</span><span style="color: rgba(0, 0, 0, 1)"> (Exception e){
   ...
}
</span><span style="color: rgba(0, 0, 255, 1)">try</span><span style="color: rgba(0, 0, 0, 1)">{
    YYY.close();
}</span><span style="color: rgba(0, 0, 255, 1)">catch</span><span style="color: rgba(0, 0, 0, 1)"> (Exception e){
   ...
}</span></pre>
</div>
<p>&nbsp;</p>
</div>
</div>
</div>
</div>
</div>
<div><span style="mso-spacerun: 'yes'; font-size: 19.219pt; font-family: Open Sans; color: rgba(51, 51, 51, 1); font-weight: bold">3.1</span><span style="mso-spacerun: 'yes'; font-size: 19.219pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">、尽可能使用局部变量 </span></div>
<div><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">调用方法时传递的参数以及在调用中创建的临时变量都保存在栈中速度较快,其他变 </span></div>
<div><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">量,如静态变量、实例变量等,都在堆中创建,速度较慢。另外,栈中创建的变量,随 </span></div>
<div><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">着方法的运行结束,这些内容就没了,不需要额外的垃圾回收。 </span></div>
<div><span style="mso-spacerun: 'yes'; font-size: 19.219pt; font-family: Open Sans; color: rgba(51, 51, 51, 1); font-weight: bold">3.2</span><span style="mso-spacerun: 'yes'; font-size: 19.219pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">、尽量减少对变量的重复计算 </span></div>
<div><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">明确一个概念,对方法的调用,即使方法中只有一句语句,也是有消耗的。所以例如下 </span></div>
<div><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">面的操作: </span></div>
<div><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">建议替换为: </span></div>
<div><span style="mso-spacerun: 'yes'; font-size: 12.8125pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">这样,在</span><span style="mso-spacerun: 'yes'; font-size: 12.8125pt; font-family: Open Sans; color: rgba(51, 51, 51, 1)">list.size()</span><span style="mso-spacerun: 'yes'; font-size: 12.8125pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">很大的时候,就减少了很多的消耗。 </span></div>
<div><span style="mso-spacerun: 'yes'; font-size: 19.2188pt; font-family: Open Sans; color: rgba(51, 51, 51, 1); font-weight: bold">3.3</span><span style="mso-spacerun: 'yes'; font-size: 19.2188pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">、尽量采用懒加载的策略,即在需要的时候才创建 </span></div>
<div><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(119, 0, 136, 1)">for </span><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(51, 51, 51, 1)">(</span><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(0, 136, 85, 1)">int </span><span style="font-size: 11.5314pt; font-family: Consolas">i = </span><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(17, 102, 68, 1)">0</span><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(51, 51, 51, 1)">; </span><span style="font-size: 11.5314pt; font-family: Consolas">i &lt; list</span><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(51, 51, 51, 1)">.</span><span style="font-size: 11.5314pt; font-family: Consolas">size</span><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(51, 51, 51, 1)">(); </span><span style="font-size: 11.5314pt; font-family: Consolas">i++</span><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(51, 51, 51, 1)">) </span></div>
<div><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(51, 51, 51, 1)">{...} </span></div>
<div><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(0, 136, 85, 1)">int </span><span style="font-size: 11.5314pt; font-family: Consolas">length = list</span><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(51, 51, 51, 1)">.</span><span style="font-size: 11.5314pt; font-family: Consolas">size</span><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(51, 51, 51, 1)">(); </span></div>
<div><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(119, 0, 136, 1)">for </span><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(51, 51, 51, 1)">(</span><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(0, 136, 85, 1)">int </span><span style="font-size: 11.5314pt; font-family: Consolas">i = </span><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(17, 102, 68, 1)">0</span><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(51, 51, 51, 1)">, </span><span style="font-size: 11.5314pt; font-family: Consolas">i &lt; length</span><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(51, 51, 51, 1)">; </span><span style="font-size: 11.5314pt; font-family: Consolas">i++</span><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(51, 51, 51, 1)">) </span></div>
<div><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(51, 51, 51, 1)">{...}</span><span style="mso-spacerun: 'yes'; font-size: 36pt; font-family: 微软雅黑; color: rgba(146, 208, 80, 1)"><br></span></div>
<div><span style="mso-spacerun: 'yes'; font-size: 19.219pt; font-family: Open Sans; color: rgba(51, 51, 51, 1); font-weight: bold">3.4</span><span style="mso-spacerun: 'yes'; font-size: 19.219pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">、异常不应该用来控制程序流程 </span></div>
<div><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">异常对性能不利。抛出异常首先要创建一个新的对象,</span><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: Open Sans; color: rgba(51, 51, 51, 1)">Throwable</span><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">接口的构造函数调用 </span></div>
<div><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">名为</span><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: Open Sans; color: rgba(51, 51, 51, 1)">fillInStackTrace()</span><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">的本地同步方 法,</span><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: Open Sans; color: rgba(51, 51, 51, 1)">fillInStackTrace()</span><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">方法检查堆栈,收集调用跟踪 </span></div>
<div><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">信息。只要有异常被抛出,</span><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: Open Sans; color: rgba(51, 51, 51, 1)">Java</span><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">虚拟机就必须调整调用堆栈,因为在处理过程中创建 了 </span></div>
<div><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">一个新的对象。异常只能用于错误处理,不应该用来控制程序流程。 </span></div>
<div><span style="mso-spacerun: 'yes'; font-size: 19.219pt; font-family: Open Sans; color: rgba(51, 51, 51, 1); font-weight: bold">3.5</span><span style="mso-spacerun: 'yes'; font-size: 19.219pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">、不要将数组声明为</span><span style="mso-spacerun: 'yes'; font-size: 19.219pt; font-family: Open Sans; color: rgba(51, 51, 51, 1); font-weight: bold">public static final </span></div>
<div><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">因为这毫无意义,这样只是定义了引用为</span><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: Open Sans; color: rgba(51, 51, 51, 1)">static final</span><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">,数组的内容还是可以随意改变的, </span></div>
<div><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">将数组声明为</span><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: Open Sans; color: rgba(51, 51, 51, 1)">public</span><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">更是一个安全漏洞,这意味着这个数组可以被外部类所改变。 </span></div>
<div><span style="mso-spacerun: 'yes'; font-size: 19.219pt; font-family: Open Sans; color: rgba(51, 51, 51, 1); font-weight: bold">3.6</span><span style="mso-spacerun: 'yes'; font-size: 19.219pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">、不要创建一些不使用的对象,不要导入一些不使用的 </span></div>
<div><span style="mso-spacerun: 'yes'; font-size: 19.219pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">类</span></div>
<div><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">这毫无意义,如果代码中出现</span><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: Open Sans; color: rgba(51, 51, 51, 1)">"The value of the local variable i is not used"</span><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">、</span><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: Open Sans; color: rgba(51, 51, 51, 1)">"The </span></div>
<div><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: Open Sans; color: rgba(51, 51, 51, 1)">import java.util is never used"</span><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">,那么请删除这些无用的内容 </span></div>
<div><span style="mso-spacerun: 'yes'; font-size: 19.219pt; font-family: Open Sans; color: rgba(51, 51, 51, 1); font-weight: bold">3.7</span><span style="mso-spacerun: 'yes'; font-size: 19.219pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">、程序运行过程中避免使用反射 </span></div>
<div><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">反射是</span><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: Open Sans; color: rgba(51, 51, 51, 1)">Java</span><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">提供给用户一个很强大的功能,功能强大往往意味着效率不高。不建议在程序 </span></div>
<div><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">运行过程中使用尤其是频繁使用反射机制,特别是 </span><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: Open Sans; color: rgba(51, 51, 51, 1)">Method</span><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">的</span><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: Open Sans; color: rgba(51, 51, 51, 1)">invoke</span><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">方法。 </span></div>
<div><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">如果确实有必要,一种建议性的做法是将那些需要通过反射加载的类在项目启动的时候 </span></div>
<div><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">通过反射实例化出一个对象并放入内存。 </span></div>
<div><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(0, 136, 85, 1)">String </span><span style="font-size: 11.5314pt; font-family: Consolas">str = </span><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(170, 17, 17, 1)">"aaa"</span><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(51, 51, 51, 1)">; </span></div>
<div><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(119, 0, 136, 1)">if </span><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(51, 51, 51, 1)">(</span><span style="font-size: 11.5314pt; font-family: Consolas">i == </span><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(17, 102, 68, 1)">1</span><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(51, 51, 51, 1)">){ </span></div>
<div><span style="font-size: 11.5314pt; font-family: Consolas">list</span><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(51, 51, 51, 1)">.</span><span style="font-size: 11.5314pt; font-family: Consolas">add</span><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(51, 51, 51, 1)">(</span><span style="font-size: 11.5314pt; font-family: Consolas">str</span><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(51, 51, 51, 1)">); </span></div>
<div><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(51, 51, 51, 1)">}</span></div>
<div><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(170, 85, 0, 1)">//</span><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: 宋体; color: rgba(170, 85, 0, 1)">建议替换成 </span></div>
<div><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(119, 0, 136, 1)">if </span><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(51, 51, 51, 1)">(</span><span style="font-size: 11.5314pt; font-family: Consolas">i == </span><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(17, 102, 68, 1)">1</span><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(51, 51, 51, 1)">){ </span></div>
<div><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(0, 136, 85, 1)">String </span><span style="font-size: 11.5314pt; font-family: Consolas">str = </span><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(170, 17, 17, 1)">"aaa"</span><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(51, 51, 51, 1)">; </span></div>
<div><span style="font-size: 11.5314pt; font-family: Consolas">list</span><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(51, 51, 51, 1)">.</span><span style="font-size: 11.5314pt; font-family: Consolas">add</span><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(51, 51, 51, 1)">(</span><span style="font-size: 11.5314pt; font-family: Consolas">str</span><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(51, 51, 51, 1)">); </span></div>
<div><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(51, 51, 51, 1)">}</span><span style="mso-spacerun: 'yes'; font-size: 36pt; font-family: 微软雅黑; color: rgba(146, 208, 80, 1)"><br></span></div>
<div><span style="mso-spacerun: 'yes'; font-size: 19.2192pt; font-family: Open Sans; color: rgba(51, 51, 51, 1); font-weight: bold">3.8</span><span style="mso-spacerun: 'yes'; font-size: 19.219pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">、使用数据库连接池和线程池 </span></div>
<div><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">这两个池都是用于重用对象的,前者可以避免频繁地打开和关闭连接,后者可以避免频 </span></div>
<div><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">繁地创建和销毁线程。 </span></div>
<div><span style="mso-spacerun: 'yes'; font-size: 19.219pt; font-family: Open Sans; color: rgba(51, 51, 51, 1); font-weight: bold">3.9</span><span style="mso-spacerun: 'yes'; font-size: 19.219pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">、容器初始化时尽可能指定长度 </span></div>
<div><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">容器初始化时尽可能指定长度,如:</span><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: Open Sans; color: rgba(51, 51, 51, 1)">new ArrayList&lt;&gt;(10); new HashMap&lt;&gt;(32); </span><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">避免容 </span></div>
<div><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">器长度不足时,扩容带来的性能损耗。 </span></div>
<div><span style="mso-spacerun: 'yes'; font-size: 19.219pt; font-family: Open Sans; color: rgba(51, 51, 51, 1); font-weight: bold">3.10</span><span style="mso-spacerun: 'yes'; font-size: 19.219pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">、</span><span style="mso-spacerun: 'yes'; font-size: 19.219pt; font-family: Open Sans; color: rgba(51, 51, 51, 1); font-weight: bold">ArrayList</span><span style="mso-spacerun: 'yes'; font-size: 19.219pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">随机遍历快,</span><span style="mso-spacerun: 'yes'; font-size: 19.219pt; font-family: Open Sans; color: rgba(51, 51, 51, 1); font-weight: bold">LinkedList</span><span style="mso-spacerun: 'yes'; font-size: 19.219pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">添加删除快 </span></div>
<div><span style="mso-spacerun: 'yes'; font-size: 19.219pt; font-family: Open Sans; color: rgba(51, 51, 51, 1); font-weight: bold">3.11</span><span style="mso-spacerun: 'yes'; font-size: 19.219pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">、使用</span><span style="mso-spacerun: 'yes'; font-size: 19.219pt; font-family: Open Sans; color: rgba(51, 51, 51, 1); font-weight: bold">Entry</span><span style="mso-spacerun: 'yes'; font-size: 19.219pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">遍历</span><span style="mso-spacerun: 'yes'; font-size: 19.219pt; font-family: Open Sans; color: rgba(51, 51, 51, 1); font-weight: bold">Map </span></div>
<div><span style="mso-spacerun: 'yes'; font-size: 12.8127pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">避免使用这种方式: </span></div>
<div><span style="mso-spacerun: 'yes'; font-size: 19.2188pt; font-family: Open Sans; color: rgba(51, 51, 51, 1); font-weight: bold">3.12</span><span style="mso-spacerun: 'yes'; font-size: 19.2188pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">、不要手动调用</span><span style="mso-spacerun: 'yes'; font-size: 19.2188pt; font-family: Open Sans; color: rgba(51, 51, 51, 1); font-weight: bold">System.gc(); </span></div>
<div><span style="mso-spacerun: 'yes'; font-size: 19.2188pt; font-family: Open Sans; color: rgba(51, 51, 51, 1); font-weight: bold">3.13</span><span style="mso-spacerun: 'yes'; font-size: 19.2188pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">、</span><span style="mso-spacerun: 'yes'; font-size: 19.2188pt; font-family: Open Sans; color: rgba(51, 51, 51, 1); font-weight: bold">String</span><span style="mso-spacerun: 'yes'; font-size: 19.2188pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">尽量少用正则表达式 </span></div>
<div><span style="mso-spacerun: 'yes'; font-size: 12.8125pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">正则表达式虽然功能强大,但是其效率较低,除非是有需要,否则尽可能少用。 </span></div>
<div><span style="mso-spacerun: 'yes'; font-size: 12.8125pt; font-family: Open Sans; color: rgba(51, 51, 51, 1)">replace() </span><span style="mso-spacerun: 'yes'; font-size: 12.8125pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">不支持正则 </span></div>
<div><span style="mso-spacerun: 'yes'; font-size: 12.8125pt; font-family: Open Sans; color: rgba(51, 51, 51, 1)">replaceAll() </span><span style="mso-spacerun: 'yes'; font-size: 12.8125pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">支持正则 </span></div>
<div><span style="mso-spacerun: 'yes'; font-size: 12.8125pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">如果仅仅是字符的替换建议使用</span><span style="mso-spacerun: 'yes'; font-size: 12.8125pt; font-family: Open Sans; color: rgba(51, 51, 51, 1)">replace()</span><span style="mso-spacerun: 'yes'; font-size: 12.8125pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">。 </span></div>
<div><span style="mso-spacerun: 'yes'; font-size: 19.2188pt; font-family: Open Sans; color: rgba(51, 51, 51, 1); font-weight: bold">3.14</span><span style="mso-spacerun: 'yes'; font-size: 19.2188pt; font-family: 宋体; color: rgba(51, 51, 51, 1)">、日志的输出要注意级别 </span></div>
<div><span style="font-size: 11.5314pt; font-family: Consolas">Map&lt;</span><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(0, 136, 85, 1)">String</span><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(51, 51, 51, 1)">,</span><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(0, 136, 85, 1)">String</span><span style="font-size: 11.5314pt; font-family: Consolas">&gt; map = </span><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(119, 0, 136, 1)">new </span><span style="font-size: 11.5314pt; font-family: Consolas">HashMap&lt;&gt;</span><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(51, 51, 51, 1)">(); </span></div>
<div><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(119, 0, 136, 1)">for </span><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(51, 51, 51, 1)">(</span><span style="font-size: 11.5314pt; font-family: Consolas">Map</span><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(51, 51, 51, 1)">.</span><span style="font-size: 11.5314pt; font-family: Consolas">Entry&lt;</span><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(0, 136, 85, 1)">String</span><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(51, 51, 51, 1)">,</span><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(0, 136, 85, 1)">String</span><span style="font-size: 11.5314pt; font-family: Consolas">&gt; entry </span><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(51, 51, 51, 1)">: </span><span style="font-size: 11.5314pt; font-family: Consolas">map</span><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(51, 51, 51, 1)">.</span><span style="font-size: 11.5314pt; font-family: Consolas">entrySet</span><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(51, 51, 51, 1)">()) { </span></div>
<div><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(0, 136, 85, 1)">String </span><span style="font-size: 11.5314pt; font-family: Consolas">key = entry</span><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(51, 51, 51, 1)">.</span><span style="font-size: 11.5314pt; font-family: Consolas">getKey</span><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(51, 51, 51, 1)">(); </span></div>
<div><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(0, 136, 85, 1)">String </span><span style="font-size: 11.5314pt; font-family: Consolas">value = entry</span><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(51, 51, 51, 1)">.</span><span style="font-size: 11.5314pt; font-family: Consolas">getValue</span><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(51, 51, 51, 1)">(); </span></div>
<div><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(51, 51, 51, 1)">}</span></div>
<div><span style="font-size: 11.5314pt; font-family: Consolas">Map&lt;</span><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(0, 136, 85, 1)">String</span><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(51, 51, 51, 1)">,</span><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(0, 136, 85, 1)">String</span><span style="font-size: 11.5314pt; font-family: Consolas">&gt; map = </span><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(119, 0, 136, 1)">new </span><span style="font-size: 11.5314pt; font-family: Consolas">HashMap&lt;&gt;</span><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(51, 51, 51, 1)">(); </span></div>
<div><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(119, 0, 136, 1)">for </span><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(51, 51, 51, 1)">(</span><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(0, 136, 85, 1)">String </span><span style="font-size: 11.5314pt; font-family: Consolas">key </span><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(51, 51, 51, 1)">: </span><span style="font-size: 11.5314pt; font-family: Consolas">map</span><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(51, 51, 51, 1)">.</span><span style="font-size: 11.5314pt; font-family: Consolas">keySet</span><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(51, 51, 51, 1)">()) { </span></div>
<div><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(0, 136, 85, 1)">String </span><span style="font-size: 11.5314pt; font-family: Consolas">value = map</span><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(51, 51, 51, 1)">.</span><span style="font-size: 11.5314pt; font-family: Consolas">get</span><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(51, 51, 51, 1)">(</span><span style="font-size: 11.5314pt; font-family: Consolas">key</span><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(51, 51, 51, 1)">); </span></div>
<div><span style="mso-spacerun: 'yes'; font-size: 11.5314pt; font-family: Consolas; color: rgba(51, 51, 51, 1)">}</span><span style="mso-spacerun: 'yes'; font-size: 36pt; font-family: 微软雅黑; color: rgba(146, 208, 80, 1)"><br></span></div><br><br>
来源:https://www.cnblogs.com/yjc1605961523/p/12462954.html
頁: [1]
查看完整版本: 使用javap生成的汇编语言