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

前端 未结 7 2054
时光取名叫无心
时光取名叫无心 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:43

    If you have a Collection (or more general an Iterable) you can use Google Guava's

    Iterables.getLast(myIterable)
    

    as handy oneliner.

提交回复
热议问题