How to replace null value of a String in java? -
i know it's dumb question still.
but want know possible replace string set null ?
string str=null; string str2= str.replace('l','o'); system.out.println(str2);
currently giving me nullpointerexception
.
i want know possible how replace value of string set null ?
if yes, how ?
help appreciated. thanks
use string.valueof()
:
string str2 = string.valueof(str).replace('l','o');
from javadoc of string.valueof(object obj)
:
if argument null, string equal "null"; otherwise, value of obj.tostring() returned.
which of course string
itself.
Comments
Post a Comment