title: Concatenation operator (+) vs. concat()
body: <p>For string concatenation we can use either the <code>concat()</code> or concat operator <code>(+)</code>.</p>
  
  <p>I have tried the following performance test and found <code>concat()</code> is faster and a memory efficient way for string concatenation.</p>
  
  <p><strong>String concatenation comparison for 100,000 times</strong>:</p>
  
  <pre><code>String str = null;
  
  //------------Using Concatenation operator-------------
  long time1 = System.currentTimeMillis();
  long freeMemory1 = Runtime.getRuntime().freeMemory();
  
  for(int i=0; i&lt;100000; i++){
      str = "Hi";
      str = str+" Bye";
  }
  long time2 = System.currentTimeMillis();
  long freeMemory2 = Runtime.getRuntime().freeMemory();
  
  long timetaken1 = time2-time1;
  long memoryTaken1 = freeMemory1 - freeMemory2;
  System.out.println("Concat operator  :" + "Time taken =" + timetaken1 +
                     " Memory Consumed =" + memoryTaken1);
  
  //------------Using Concat method-------------
  long time3 = System.currentTimeMillis();
  long freeMemory3 = Runtime.getRuntime().freeMemory();
  for(int j=0; j&lt;100000; j++){
      str = "Hi";
      str = str.concat(" Bye");
  }
  long time4 = System.currentTimeMillis();
  long freeMemory4 = Runtime.getRuntime().freeMemory();
  long timetaken2 = time4-time3;
  long memoryTaken2 = freeMemory3 - freeMemory4;
  System.out.println("Concat method  :" + "Time taken =" + timetaken2 +
                     " Memory Consumed =" + memoryTaken2);
  </code></pre>
  
  <p><strong>Result</strong></p>
  
  <pre><code>Concat operator: Time taken = 31; Memory Consumed = 2259096
  Concat method  : Time taken = 16; Memory Consumed = 299592
  </code></pre>
  
  <p><strong>If <code>concat()</code> is faster than the operator then when should we use concatenation operator <code>(+)</code>?</strong></p>