【抽取對象屬性】抽取對象集合的屬性並以逗號隔開

需求:給定一組對象集合,抽取這個List中每一個對象的單獨的屬性並且轉成String字符串

 private String getNameLists(List<Student> studentList) {
        Object[] objects = studentList.stream().map(Student::getName).toArray();
        //StringUtil 引用自-import org.apache.commons.lang.StringUtils;
        String busnessData = StringUtils.join(objects, ",");
        return busnessData;
    }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章