I wish to replace the code below using java8 .stream()
or .foreach(). However I am having trouble doing this.
Its probably very easy, but I'm finding the functional way of thinking a struggle :)
I can iterate, no problem but the but returning the modified string is the issue due to mutability issues.
Anyone have any ideas ?
List<String> toRemove = Arrays.asList("1", "2", "3");
String text = "Hello 1 2 3";
for(String item : toRemove){
text = text.replaceAll(item,EMPTY);
}
Thanks !
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…