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 stringa = "11111110000000000";
  13. List<String> result = new ArrayList<>();
  14.  
  15. for (int endIndex = stringa.length(); endIndex >= 0; endIndex -= 4) {
  16. int beginIndex = Math.max(0, endIndex - 4);
  17. String str = stringa.substring(beginIndex, endIndex);
  18. //System.out.println(str);
  19. result.add(0, str);
  20. }
  21.  
  22. System.out.println(result);
  23. }
  24. }
Success #stdin #stdout 0.07s 3359744KB
stdin
Standard input is empty
stdout
[1, 1111, 1100, 0000, 0000]