String reason immutable

1 a string may be used by multiple objects. One change does not affect the other

2 strings are widely used in many places, for example, to open a network connection, you can set the host name and port number as a string, you can pass a string as a URL database to open the database connection, you can pass the file name as parameters passed to the file I / O classes to open any file in Java. If you can change. It can become dangerous

3 can safely share many threads

4 allows String cache hash code

Class loading mechanism 5 is used

Guess you like

Origin www.cnblogs.com/jayjie/p/11573217.html