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

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

    One liner (no need for stream;):

    Object lastElement = list.get(list.size()-1);
    

提交回复
热议问题