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. class Person {
  8. private String name;
  9. private int age;
  10.  
  11. public Person(String name, int age) {
  12. this.name = name;
  13. this.age = age;
  14. }
  15.  
  16.  
  17. }
  18.  
  19. /* Name of the class has to be "Main" only if the class is public. */
  20. class Ideone
  21. {
  22. public static void main (String[] args) throws java.lang.Exception
  23. {
  24. Map<String, Object> parameters = new HashMap<>();
  25. Person person = new Person("Alice", 30);
  26. // Add key-value pairs to the map
  27. parameters.put("key1", "value1");
  28. parameters.put("key2", 123);
  29. parameters.put("key3", true);
  30. parameters.put("key4", person);
  31.  
  32. // Convert the map to a string
  33. String parametersAsString = parameters.toString();
  34.  
  35. // Display or use the resulting string
  36. System.out.println(parameters);
  37. }
  38. }
Success #stdin #stdout 0.12s 54764KB
stdin
Standard input is empty
stdout
{key1=value1, key2=123, key3=true, key4=Person@5caf905d}