Just don’t do it.
- Don’t create new strings
- Don’t instantiate resource heavy classes in a loop
- Mind the unnecessary auto-boxing
- Make use of static fields or caching
- Make use of singleton pattern
- Opt for immutable objects and reuse them.
This post is based on Joshua Bloch Effective Java Third Edition (get it on Amazon: https://www.amazon.com/Effective-Java-3rd-Joshua-Bloch/dp/0134685997)
