1. 程式人生 > >字串以逗號拼接成另一個字串儲存

字串以逗號拼接成另一個字串儲存

StringBuilder sb = new StringBuilder();
StringBuilder sbId = new StringBuilder();
for (LMSLabConfigLabClassGroup lmsLabConfigLabClassGroup:lmsLabConfigLabClassGroups) {
    LabClassLMSGroup labClassLMSGroup = lmsLabConfigLabClassGroup.getLabClassGroup();
    if (labClassLMSGroup != null) {
        if 
(sb.length() > 0) { sb.append(","); } sb.append(labClassLMSGroup.getName()); if (sbId.length() > 0) { sbId.append(","); } sbId.append(labClassLMSGroup.getId()); } } dto.setGroupName(sb.toString()); dto.setGroupId(sbId.toString());