String is final & immutable because...
- String pool stores only one copy hence memory is saved
- Security: username & password like sensitive info received from external sources cannot modified in implementation (i.e. after/before validation
- Helps in Caching & Hashing i.e. hash value of the String is cached and returned (as it never changes)
- Above #1, #2 & #3, helps in improving the performance
- As strings are immutable, they are thread safe hence helps in synchronization
No comments:
Post a Comment