2017-02-24 66 views
0

我知道谓词是指定ArrayList的哪个对象必须被删除。而不是删除我想设置为null这些对象。谓词设置而不是删除

喜欢

arrayList.setIf(比如说myPredicate,NULL); 而不是 arrayList.removeIf(myPredicate)

我准备了这么多的谓词,所以我不想浪费它。

+0

你必须自己编写它。它不存在。 – Seelenvirtuose

+2

[如何在集合中有条件地替换值,例如replaceIf(谓词)?](http://stackoverflow.com/questions/35807818/how-to-replace-a-value-conditionally-in -a信息收集等-AS-replaceifpredicat) – Calculator

回答

0

你必须写你自己的逻辑,他们没有这样的功能来处理这样的场景,但仍然可以做一些事情是这样的:

yourList.stream().map(y -> { 
    if (y.Something().equals("something")) 
     return y; 
     else 
      return null; 
    }).collect(toList());