java的List调用toString以后去除两端[]括号

阅读 9

2023-09-06

原始代码:

List<Integer> vids=new ArrayList<>();
            if(planList != null && planList.size() > 0){
                for (int i = 0; i < planList.size(); i++) {
                    VoicePlanListEntity voicePlanListEntity = new VoicePlanListEntity();
                    voicePlanListEntity.setVpid(voicePlanEntity.getId());
                    voicePlanListEntity.setVid(Integer.valueOf(planList.get(i).toString()));
                    voicePlanListEntity.setSort(i);
                    this.voicePlanListService.insert(voicePlanListEntity);

                   vids.add(Integer.valueOf(planList.get(i).toString()));
                }
               
                voicePlanEntity.setVid(vids.toString());
                voicePlanService.update(voicePlanEntity);
                //增加语音id
            }

去除方式:

将下面代码:

  voicePlanEntity.setVid(vids.toString());

更换为:

 voicePlanEntity.setVid(StringUtils.strip(vids.toString(),"[]"));

精彩评论(0)

0 0 举报