# String

  1. String is immutable
    • String class uses final keyword, so no class can inherit it
    • it doesn't have any method to modify the string
  2. String is treated as a const, it's thread safe
  3. Whenever you do strig concatenation, appending one string to the end of the string (uses + operator), it actually creates a new String object, and then point to the String object.
public final class String implements java.io.Serializable, Comparable<String>, CharSequence { 
	private final char value[]; //... }
use "+" operator or StringBuilder?

Use StringBuilder when a mutable string is needed

# StringBuffer

  1. It's thread safe because it is Synchronized
  2. It has methods append , insert , indexOf etc.

# StringBuilder

  1. It's not thread safe, not synchronized
  2. It has methods append , insert , indexOf etc.

# Summary

  1. String is immutable
  2. StringBuilder and StringBuffer are mutable
  3. use String if you don't need to handle too much data
  4. use StringBuilder in single-thread if you have to deal with lots of data
  5. use StringBuffer in multi-thread if you have to deal with lots of data