Get last element of Stream/List in a one-liner

前端 未结 7 1966
时光取名叫无心
时光取名叫无心 2020-12-04 15:50

How can I get the last element of a stream or list in the following code?

Where data.careas is a List:

CArea f         


        
相关标签:
7条回答
  • 2020-12-04 16:48

    Another way to get the last element is by using sort.

        Optional<CArea> num=data.careas.stream().sorted((a,b)->-1).findFirst();
    
    0 讨论(0)
提交回复
热议问题