List<Integer> idList = Arrays.stream(ids.split(",")).map(Integer::valueOf).collect(Collectors.toList());
String string2 = list2.stream().collect(Collectors.joining(","));
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
public class IdListUtils {
public static String idList2String(List<Integer> idList) {
return StringUtils.join(idList.toArray(), ",");
}
public static List<Integer> string2IdList(String ids) {
return Arrays.stream(ids.split(",")).map(Integer::valueOf).collect(Collectors.toList());
}
}
对象list转为对象中字段的list
List<SysUserRole> sysUserRoleList = xxx;
List<Integer> roleIds = sysUserRoleList.stream().mapToInt(SysUserRole::getRoleId).boxed().collect(Collectors.toList());