Finding the median value from a List of objects using Java 8

后端 未结 4 1660
遇见更好的自我
遇见更好的自我 2020-12-11 04:28

I have two classes that are structured like this:

public class Company {
     private List person;
     ...
     public List getP         


        
4条回答
  •  死守一世寂寞
    2020-12-11 05:18

    You can use lambda expression reduction to get the median of list:

    Integer median = Person
       .stream()
       .map(Person::getAge)
       .filter(n -> n.length()/2);
    

提交回复
热议问题