首页 > 代码库 > java Map Optional

java Map Optional

技术分享
public Map<Integer,String> getCity(List<Integer> cityIds) throws  Exception{
        Map<Integer,String> cityNames =   new LinkedHashMap<>();
        List<CityMapping> citys = this.getAllCity();
        for(Integer cityId : cityIds) {
            Optional<CityMapping> cityItem = citys.stream().filter(x -> x.getCityId().equals(cityId) ).findFirst();
            if(cityItem.isPresent()){
                cityNames.put(cityId,cityItem.get().getCityName());
            }
        }
        return  cityNames;
    }
Optional

 

java Map Optional