samedi 7 juillet 2018

Java: Negating contains

I have an if-statement in my code that checks if a UUID to String is among a List of UUIDs as String.
It works, but I am having some problems negating it.

Based on this question I have tried adding !, but this results in a Null Pointer Exception:
Java - Opposite of .contains (does not contain)

if (n.getData().getList().contains(m.getId().toString()))
{
    // this works fine
}

if (!n.getData().getList().contains(m.getId().toString()))
{
    // this throws Null Pointer Exception
}

Neither the List nor the String I am checking for are empty.
How do I properly negate this, so I do not have to resort to an else block?

Aucun commentaire:

Enregistrer un commentaire