fork download
  1. import java.util.regex.Matcher;
  2. import java.util.regex.Pattern;
  3. import java.util.Map;
  4. import java.util.HashMap;
  5.  
  6. public class Main
  7. {
  8. static void processString(String line)
  9. {
  10. Pattern p = Pattern.compile("(1\\%?|2|3|4)");
  11. Matcher m = p.matcher(line);
  12. Map<String, String> map = new HashMap<>();
  13. while(m.find()) map.put("AAA" + m.group(), m.group());
  14. System.out.println(map);
  15. }
  16.  
  17. public static void main(String[] args)
  18. {
  19. processString(" 1 2 3 4 4 2 1% 1% 1 2 3 ");
  20. }
  21. }
Success #stdin #stdout 0.09s 27944KB
stdin
Standard input is empty
stdout
{AAA1%=1%, AAA3=3, AAA4=4, AAA1=1, AAA2=2}