fork(3) download
  1. import java.util.*;
  2. import java.util.stream.Collectors;
  3.  
  4.  
  5. class Ideone
  6. {
  7. public static void main (String[] args) {
  8. Map<String , String> map = new HashMap<>();
  9. map.put("11", "eleven"); // etc
  10. String str = "one two three 11 foo";
  11.  
  12. str = Arrays.stream(str.split(" "))
  13. .map(s -> map.getOrDefault(s, s))
  14. .collect(Collectors.joining(" "));
  15.  
  16. System.out.println(str);
  17.  
  18. }
  19. }
Success #stdin #stdout 0.21s 320832KB
stdin
Standard input is empty
stdout
one two  three   eleven  foo