Replace Null Values in Arraylist

PandaRasta :

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.

Gustavo :

in this line you are comparing the value at position x with the String null and not "with a null value":

if(Data.get(x).equals("null") == true)

Replace this comparison by:

if(Data.get(x) == null)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=309228&siteId=1