Reputation: 709
Iam new to java . Iam having my xml content as below
<Configuration>
<A>OFF</A>
<B>OFF</B>
<C>OFF</C>
<D>OFF</D>
<E></E>
<F>200</F>
<AB>
<G>10001</G>
<H>10002</H>
<I>10003</I>
<J>10004</J>
</AB> ............. ......
I want to change the value of <B>
tag to ON
. How can i achieve this? I am using the below code
String config2=config;
if(config2.contains("<B>OFF</B>"))
{
config2=config2.replace("<B>OFF</B>","<B>ON</B>");
return config2;
}
else
{
return true;
}
thanks in advance
Upvotes: 0
Views: 114
Reputation: 4534
Your method can not return two different types at same time.
return config2
in else
part too if the return type of your method is String
.
else
{
return config2;
}
If the string contains the chars then edit the config2
and return it else return same String
without editing
Upvotes: 1