i'm trying to replace null values in my arrayList but I get exception
java.lang.NullPointerException
I have tried different way :
Data.replaceAll(s -> s.replaceAll(" null", ""));
And :
for(int x = 0; x < Data.size(); x++)
{
if(Data.get(x).equals("null") == true)
{
Data.set(x, "");
}
}
And :
for(int x = 0; x < Data.size(); x++)
{
if(Data.get(x).equals(null) == true)
{
Data.set(x, "");
}
}
but an exception is throw java.lang.NullPointerException
Here is an exemple of my arrayList:
[0050568D6268, null, A001, A, T3, Principal, COL - Test, 4-Lock, Com. On Stage, Social, RDC, null, null, null, null, -1, null, -1, 0, -1, 99, 53]
I'm looking for any help thanks.
I think you want to use map() here:
// given list data
data = data.stream()
.map(s -> Objects.isNull(s) ? "" : s)
.collect(Collectors.toList());
This would return a list identical to the input, except with all null values replaced by empty string.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With