8.Q. Is String thread-safe in Java?

Category: JAVA STRING INTERVIEW QUESTIONS AND ANSWERS

Yes, In Java String is Thread-Safe. The main reason for thread-safety of String is immutability of String . Once String object is created , its character sequence and internal state cannot be modified or altered . Threads can only read from a String object but never write to it , so there is no risk of race conditions , data corruption . Multiple threads can safely share the exact same string instance simultaneously without explicit synchronization . Hence Java String are thread-safe.

Leave a Reply

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