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

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

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

android - How to create dynamically Fragment pager adapter -