报错的很大原因可能是因为使用 Arrays.asList(" “)方法。
Arrays.asList(” ")生成的是新的List,而这个List是内部类的形式,使用的是final修饰,不支持add和remove。
解决方案很多,这里推荐一种stream方法。
List<String> words = Arrays.asList("中国|江苏省|徐州市|电信");
List<String> collect = words.stream().map(item -> item.split("\\|")).flatMap(Arrays::stream).collect(Collectors.toList());
或者自己写循环转换也可以。