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

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -