Java8中List的removeif()函数的使用示例

Posted <・)))><<

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Java8中List的removeif()函数的使用示例相关的知识,希望对你有一定的参考价值。

代码:

import java.util.List;
import java.util.function.Predicate;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.anbank.eva.po.RptEbankMerchantDetail;
import com.anbank.eva.service.RptEbankMerchantDetailService;

@RestController
@RequestMapping("/RPT_EBANK_MERCHANT_DETAIL")
public class RptEbankMerchantDetailController {

    @Autowired
    private RptEbankMerchantDetailService rptEbankMerchantDetailService;
    
    @RequestMapping("/all")
    public List<RptEbankMerchantDetail> getAllRptEbankMerchantDetails() {
        List<RptEbankMerchantDetail> list = this.rptEbankMerchantDetailService.getAllRptEbankMerchantDetails();
        return list;
    }
    
    @RequestMapping("/result")
    public List<RptEbankMerchantDetail> getRptEbankMerchantDetails(@RequestParam(value="orgId", required=false)  String orgId,
                                                                        @RequestParam(value="startDate", required=false) String startDate,
                                                                        @RequestParam(value="endDate", required=false) String endDate,
                                                                        @RequestParam(value="merId", required=false) String merId
                                            ) {
        List<RptEbankMerchantDetail> list = this.rptEbankMerchantDetailService.getAllRptEbankMerchantDetails();
        Predicate<RptEbankMerchantDetail> predicate = (ele) -> {
            if (orgId != null && orgId.equals(ele.getORG_CODE()) == false)
                return true;
            if (startDate != null && startDate.compareTo(ele.getCREATE_DT()) > 0)
                return true;
            if (endDate != null && endDate.compareTo(ele.getCREATE_DT()) < 0)
                return true;
            if (merId != null && merId.equals(ele.getMER_ID()) == false)
                return true;
            return false;
        };
        list.removeIf(predicate);
        return list;
    }
}

以上是关于Java8中List的removeif()函数的使用示例的主要内容,如果未能解决你的问题,请参考以下文章

Java8 List集合移除满足条件的元素

java8 数据集过滤removeIf和filter

List.removeIf 出错 - 数组中的第 K 个最大元素

Java 8 数据过滤,removeIf 和 filter 别用错了!!

RemoveIf 产生异常,为啥? [复制]

有条件地从Java 8中的List中删除元素[重复]