توضیح در مورد ایجاد String با یا بدون استفاده از new در جاوا

Q1: What is difference between create String with the new keyword or without a new keyword?

  1. String s1 = new String("NIIT");
  2. String s2 = "NIIT";
the first statement will create the object of string type without searching anywhere.
the second statement will search String Constant Pool, the same content if found, it will reference the existing object without creating a new one, else will be created new object.

Q2: What is string constant pool? It is a special memory location where the strings had been created.
نظرات 0 + ارسال نظر
برای نمایش آواتار خود در این وبلاگ در سایت Gravatar.com ثبت نام کنید. (راهنما)
ایمیل شما بعد از ثبت نمایش داده نخواهد شد