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. String[]data = {"go", "go" , "go" , "stop", "go" , "go" };
  13. ArrayList<String> tmp = new ArrayList<>();
  14. for (int h = 0; h < data.length; h++) {
  15. int count = 1;
  16. while(h + count < data.length && data[h].equals(data[h+count]))
  17. count++;
  18. tmp.add(data[h] + "(" + count + ")");
  19. h += count - 1;//Update h to skip identical element
  20. }
  21. System.out.println(tmp);
  22. }
  23. }
Success #stdin #stdout 0.1s 320320KB
stdin
Standard input is empty
stdout
[go(3), stop(1), go(2)]