1. import java.util.HashMap;
  2. import java.util.Map;
  3. public class URLParameterMonitor {
  4. private Map<String, String> currentParams = new HashMap<>();
  5. public void addParameter(String key, String value) {
  6. currentParams.put(key, value);
  7. }
  8. public String getParameter(String key) {
  9. return currentParams.getOrDefault(key, null); // Return null if key not found
  10. }
  11. public void removeParameter(String key) {
  12. currentParams.remove(key);
  13. }
  14. public Map<String, String> getCurrentParams() {
  15. return new HashMap<>(currentParams); // Return a copy to prevent external modification
  16. }
  17. public static void main(String[] args) {
  18. URLParameterMonitor monitor = new URLParameterMonitor();
  19. // Example usage:
  20. monitor.addParameter("name", "John Doe");
  21. monitor.addParameter("age", "30");
  22. System.out.println("Name: " + monitor.getParameter("name")); // Output: John Doe
  23. System.out.println("Age: " + monitor.getParameter("age")); // Output: 30
  24. System.out.println("City: " + monitor.getParameter("city")); // Output: null
  25. monitor.removeParameter("age");
  26. System.out.println("Age after removal: " + monitor.getParameter("age")); // Output: null
  27. Map<String, String> params = monitor.getCurrentParams();
  28. System.out.println("Current parameters: " + params);
  29. }
  30. }

Add your comment