search

Home  >  Q&A  >  body text

java - String s = new String("xyz");创建了几个String Object?

黄舟黄舟2802 days ago1388

reply all(3)I'll reply

  • 怪我咯

    怪我咯2017-04-18 09:34:25

    If there is xyzthis object in your string constant pool, one object is created
    If not, two objects are created

    reply
    0
  • ringa_lee

    ringa_lee2017-04-18 09:34:25

    First check if there is 'xyz' in the constant pool. If not, create it.
    Then create a new String whose reference points to xyz in the constant pool.
    So there are 1 or 2.

    reply
    0
  • 迷茫

    迷茫2017-04-18 09:34:25

    Two objects are created

    reply
    0
  • Cancelreply