string objects

Discussion in 'Strings, I/O, Formatting, Parsing' started by thiyagaraj04, Apr 4, 2013.

  1. thiyagaraj04

    thiyagaraj04 New Member

    Hi all
    i'm new to java ,my Question is
    case 1:
    String a="hello";
    String b="world";

    Case 2:
    String a="hello";
    a=new String("world");

    i would like to know how many objects be created in each case. because String is immutable so once value is assigned to it that object cannot be reused(to my under standing(else correct me please))

  2. prasanthi

    prasanthi New Member

    Case 1 : 3 objects Case 2 : 2 objects
  3. kritesh anand

    kritesh anand New Member


    Case 1 st is not valid and Case 2nd is ok and you will get world output. If you want to learn new things and concepts for advance java training then learn from training in lucknow
  4. anneroberts

    anneroberts Member

    String Literals. A string strict will be zero or that's only the tip of the iceberg characters encased over single alternately twofold citation marks. A string strict need an essential (primitive) information sort of string. An string object will be made Toward utilizing those new Operator, and need a information kind of object.

Share This Page