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 str = "01041200"
  13. + "0203119"
  14. + "0312181225100411"
  15. + "0403111"
  16. + "0500"
  17. + "0623 "
  18. + "07164130140000000272"
  19. + "08042012"
  20. + "0900"
  21. + "10010"
  22. + "1103121"
  23. + "12042982"
  24. + "1300";
  25. Map<String, String> tagValueMap = new HashMap<>();
  26. int tagLength = 2;
  27. int lengthLength = 2;
  28. int index = 0;
  29. while(index < str.length()) {
  30. String tag = str.substring(index, index+tagLength);
  31. int length = Integer.parseInt(str.substring(index+tagLength,index+tagLength+lengthLength));
  32. String value = str.substring(index+tagLength+lengthLength, index+tagLength+lengthLength+length);
  33. tagValueMap.put(tag, value);
  34. index += length +tagLength+lengthLength;
  35. }
  36. System.out.println(tagValueMap);
  37. }
  38. }
Success #stdin #stdout 0.04s 2184192KB
stdin
Standard input is empty
stdout
{11=121, 01=1200, 12=2982, 02=119, 13=, 03=181225100411, 04=111, 05=, 06=                       , 07=4130140000000272, 08=2012, 09=, 10=0}