fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. List<String> words = new ArrayList<>();
  13.  
  14. words.add("Kane");
  15. words.add("Cane");
  16. words.add("Fame");
  17. words.add("Dame");
  18. words.add("Lame");
  19. words.add("Same");
  20.  
  21. marklength4(words);
  22.  
  23. System.out.println(words);
  24.  
  25. }
  26.  
  27. public static void marklength4(List<String> themarklength){
  28. ListIterator<String> lit =
  29. themarklength.listIterator(themarklength.size());
  30. boolean shouldInsert = false;
  31. while(lit.hasPrevious()) {
  32. if (shouldInsert) {
  33. lit.add("****");
  34. lit.previous();
  35. shouldInsert = false;
  36. }
  37. final String n = lit.previous();
  38. shouldInsert = (n.length() == 4);
  39. }
  40. if (shouldInsert) {
  41. lit.add("****");
  42. }
  43. }
  44.  
  45. }
Success #stdin #stdout 0.07s 380160KB
stdin
Standard input is empty
stdout
[****, Kane, ****, Cane, ****, Fame, ****, Dame, ****, Lame, ****, Same]