martes, junio 01, 2010

Java Best Practices - Concat String

NORMAL PRACTICE
   1:  public class Main {
   2:      public static void main(String[] args) {
   3:          String text = "Hello" + " World";
   4:      }
   5:  }
BEST PRACTICE
Not Thread-safe
   1:      StringBuilder sb = new StringBuilder();
   2:      sb.append("Hello ");
   3:      sb.append("World");
Thread-Safe
   1:      StringBuffer sb = new StringBuffer();
   2:      sb.append("Hello ");
   3:      sb.append("World");

blog comments powered by Disqus

Entradas populares