Java-Arrays.asList-字符串转list-注意需要没有重写add remove方法-需再转一次
/**
* https://blog.csdn.net/bsmmaoshenbo/article/details/86590279
*
* Exception in thread "main" java.lang.UnsupportedOperationException
* at java.util.AbstractList.remove(AbstractList.java:161)
* at java.util.AbstractList$Itr.remove(AbstractList.java:374)
* at java.util.AbstractCollection.removeAll(AbstractCollection.java:376)
* at cn.jiangjiesheng.edu.service.train.EduTrainImplementService.main(EduTrainImplementService.java:1941)
* @param args
*/
public static void main(String[] args) {
//这个会错误
List<String> dbUserIdAllList = Arrays.asList("admin_51,anquanwuyou".split(","));
//需要这样包一层
dbUserIdAllList = new ArrayList<>(dbUserIdAllList);
List<String> sendedUserIdAllList = Lists.newArrayList("admin_51","anquanwuyou");
if (CollectionUtils.isNotEmpty(sendedUserIdAllList)) {
log.info("dbUserIdAllList:{}",JSON.toJSONString(dbUserIdAllList));
log.info("sendedUserIdAllList:{}",JSON.toJSONString(sendedUserIdAllList));
dbUserIdAllList.removeAll(sendedUserIdAllList);
}
}
正文到此结束