1.

Is String thread-safe in Java?

Answer»

Strings are immutable objects, which means they can't be changed or altered once they've been created. As a result, whenever we manipulate a String OBJECT, it creates a new String rather than modifying the original string object. In Java, every immutable object is thread-safe, which means String is also thread-safe. As a result, MULTIPLE THREADS can access a string. For INSTANCE, if a thread MODIFIES the value of a string, instead of modifying the existing one, a new String is created, and therefore, the original string object that was shared among the threads remains unchanged.



Discussion

No Comment Found