will two strings with same content be stored in the same memory location?

前端 未结 9 1173
慢半拍i
慢半拍i 2020-11-27 19:29

This is a question that I got in an interview.

I\'ve two strings defined as

String s1=\"Java\";
String s2=\"Java\";

My question i

9条回答
  •  情书的邮戳
    2020-11-27 20:06

    YES, Andrew Hare was answer on stack overflow in this link https://stackoverflow.com/a/2486195/4835894.

    Basically, a string intern pool allows a runtime to save memory by preserving immutable strings in a pool so that areas of the application can reuse instances of common strings instead of creating multiple instances of it.

提交回复
热议问题