Why String is immutable in Java

Tutorials Shared by the Internet Community


Why String is immutable in Java


  • Total Hits - 36236

  • Total Votes - 127 votes

  • Vote Up - 54 votes

  • Vote Down - 73 votes

  • Domain - javarevisited.blogspot.com

  • Category - Computer Basics/Computer Basics

  • Submitted By - Javin Paul

  • Submitted on - 2011-01-22 15:39:34


This is one of the most popular interview question on String in Java which starts with discussion of What is immutable object , what are the benefits of immutable object , why do you use it and which scenarios do you use it.

It can also come once interviewee answers some preliminarily strings questions e.g. What is String pool , What is the difference between String and StringBuffer , What is the difference between StringBuffer and StringBuilder etc.

Though there could be many possible answer for this question and only designer of String class can answer this , I think below two does make sense    More detail...

Broken  |   Tweet  |   Facebook  |     |   Save  |   Liked  |   Down

E-Books Store