ابدأ بالتواصل مع الأشخاص وتبادل معارفك المهنية

أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.

متابعة

When string class is immutable, why isn't there any error occurred when we try to concatenate a particular string?

user-image
تم إضافة السؤال من قبل Advaitha Chidurala , Teacher , Little Masters Abacus
تاريخ النشر: 2013/09/17
ashim anand
من قبل ashim anand

because from String class concatenate operation is not perform on perticular string object  but concatenate on new object, same object is not modified  , operation is perforned on new object rather than same object.

Ashok Yadav
من قبل Ashok Yadav , trainee , S.O Infotech Pvt. Ltd.

for eg

String s="hello";

s=s+" Ashok";

in the first line it s will point to address where hello is stored and in2nd line same 's' is now point to hello Ashok

thus the memory buffer wil now have hello and hello ashok two string. earlier s points to hello and later will to hello ashok

By doing string class concatenate operation if current object is going to modify then only  it stores the result in a new object  and  returning it refernce  ,.unlike if we concate using + operator always it returns new object irrespective of current object is modifed or not  

المزيد من الأسئلة المماثلة

هل تحتاج لمساعدة في كتابة سيرة ذاتية تحتوي على الكلمات الدلالية التي يبحث عنها أصحاب العمل؟