在guava庫中,自帶了過濾器(filter)的功能,能夠用來對list進行轉換app
/** *@description * 利用guava中集合filter 實現list的轉換 *@date 2016年11月3日 *@author kevin *@param entityList *@return * poList */ private List<StoryStyleDictionaryPo> entityListToPoList(List<StoryStyleDictionaryEntity> entityList){ List<StoryStyleDictionaryPo> dto_list = null; if(entityList != null && !entityList.isEmpty()){ // 方式一 /*Function<StoryStyleDictionaryEntity, StoryStyleDictionaryPo> function = new Function<StoryStyleDictionaryEntity, StoryStyleDictionaryPo>() { @Override public StoryStyleDictionaryPo apply(StoryStyleDictionaryEntity input) { StoryStyleDictionaryPo xbnAdminCompanyListDTO = new StoryStyleDictionaryPo(); //DTO內容copy制Bean對象中 BeanUtils.copyProperties(input,xbnAdminCompanyListDTO); return xbnAdminCompanyListDTO; } }; Iterable<StoryStyleDictionaryPo> transform = Iterables.transform(entityList, function); dto_list = Lists.newArrayList(transform);*/ // // 方式二 dto_list = Lists.newArrayList(Iterables.transform(entityList,new Function<StoryStyleDictionaryEntity, StoryStyleDictionaryPo>() { @Override public StoryStyleDictionaryPo apply( StoryStyleDictionaryEntity input) { //建立Bean對象 StoryStyleDictionaryPo xbnAdminCompanyListDTO = new StoryStyleDictionaryPo(); //DTO內容copy制Bean對象中 BeanUtils.copyProperties(input,xbnAdminCompanyListDTO); return xbnAdminCompanyListDTO; } })); } return dto_list; }