fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.util.stream.Collectors;
  7.  
  8. /* Name of the class has to be "Main" only if the class is public. */
  9. class Ideone
  10. {
  11. public static void main (String[] args) throws java.lang.Exception
  12. {
  13. String task1 = "This this test is a test";
  14. String[] words = task1.split("\\s+");
  15. Map<String, Integer> wordsCount = Arrays.stream(words)
  16. .collect(Collectors.toMap( a -> a,
  17. a -> 1,
  18. Integer::sum
  19. )
  20. );
  21. String answer1 = Arrays.stream(words)
  22. .map(a -> wordsCount.get(a).equals(1)
  23. ? a
  24. : "<strong>" + a + "</strong>")
  25. .collect(Collectors.joining(" "));
  26.  
  27. System.out.println(answer1);
  28. // your code goes here
  29. }
  30. }
Success #stdin #stdout 0.1s 711680KB
stdin
Standard input is empty
stdout
This this <strong>test</strong> is a <strong>test</strong>