2016-03-03 37 views
0

因此,我有一個列表,它們共有空值。我需要排除那些沒有空值的列表。如何從列表中過濾空值以將它傳遞給比較器

所以我是這麼有:

foreignList.stream().filter(c -> c.getForeignBureauInquiryDocSlot() != null); 
Collections.sort(foreignList, ((DocumentSorting o1, DocumentSorting o2) -> o1.getForeignBureauInquiryDocSlot() - o2.getForeignBureauInquiryDocSlot())); 

但它返回的NullPointerException

+0

列表中的對象類型是什麼? –

回答

0

也許這種方法可以幫助你。

list.removeAll(Collections.singleton(null)); 
Collections.sort(list); 
相關問題