Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis+ 2
Y string is immutable
tell me
2 Respostas
+ 10
check it once!!
https://code.sololearn.com/cRFSi8C88PYG/?ref=app
+ 1
StringĀ is immutable for several reasons, here is a summary:
Security: parameters are typically represented asĀ StringĀ in network connections, database connection urls, usernames/passwords etc. If it were mutable, these parameters could be easily changed.SynchronizationĀ and concurrency: making String immutable automatically makes them thread safe thereby solving the synchronization issues.Caching: when compiler optimizes your String objects, it sees that if two objects have same value (a="test", and b="test") and thus you need only one string object (for both a and b, these two will point to the same object).Class loading:Ā StringĀ is used as arguments for class loading. If mutable, it could result in wrong class being loaded (because mutable objects change their state).
answer source:
http://stackoverflow.com/questions/22397861/why-is-string-immutable-in-java