String vs StringBuilder vs StringBuffer

FeatureString StringBuilderStringBuffer
IntroductionJDK 1JDK 5JDK 1
MutabilityImmutableMutableMutable
Thread SafetyThread safeNot Thread safe Thread safe
Memory EfficiencyHighEfficientLess Efficient
PerformanceHigh(No synchronisation)High (No synchronisation)Low(Due to synchronisation)
Usage It is used when we want immutability.This is used when thread safety is not required.This is used when thread safety is required.

Author: Susheel kumar

Leave a Reply

Your email address will not be published. Required fields are marked *