Using this code :
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.List;
import java.util.stream.Collectors;
public class Replace
{
public static void main(String args[]){
Map<String , String> map = new HashMap<String , String>();
map.put("eleven", "11");
String str = "replace the 11";
List<String> ls = Arrays.asList(str.split(" "));
ls.stream().map(m -> map.entrySet().forEach(e -> m.replaceAll(m , e.getKey())));
}
}
I'm attempting to replace occurrences of "11" in the String str with "eleven". So str should be converted to "replace the eleven".
But I'm receiving compiler error :
Multiple markers at this line
- Type mismatch: cannot convert from Stream<Object> to
<unknown>
- Cannot return a void result
How to replace occurrences of keys in map that match string values ?