2

in java if you define a string which containes a array of char that already exist it will be bount to the same refrence which i assumed it scanned the memory from bottom to top to search but on further inspection its the first string initiated with that string even if that string has a "higher" adress so i wondered how the java interperter searches for existing strings i checked the variable's adress using

System.identityHashCode()

and used a basic string for testing like "hello"

  • 1
    Already answered here: https://stackoverflow.com/questions/35498336/how-does-java-implement-string-pooling – Cyril G. Sep 03 '20 at 10:56
  • i couldnt see the answer to this exact question my question is assuming i have a "hello" string in memory at x adress and i have a "hello" in memory in a diffrent address lets call it y how would java decide which one to use if i create a new hello stirng without the new key word – Barak Gzlee Sep 03 '20 at 11:04
  • This depends of the JVM implementation, you need to check JVM specs you are using. – Cyril G. Sep 03 '20 at 11:09

0 Answers0