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. void doHashMap() {
  11. Map<String, Object> profile = new HashMap<String, Object>() {
  12. {
  13. put("name", "John Lennon");
  14. put("email", "foobar@gmail.com");
  15. put("phone", "+81-90-0000-0000");
  16. put("occupation", new String[] { "Programmer", "System Engineer" });
  17. put("language", new String[] { "Japanese", "English", "Spanish", "Chinease" });
  18. put("hobby", new String[] { "Photography", "Traveling", "Fishing", "Onsen" });
  19. }
  20. };
  21.  
  22. System.out.println(profile.get("name"));
  23. for (String occupation : (String[]) profile.get("occupation")) {
  24. System.out.println(occupation);
  25. }
  26. }
  27.  
  28. void doClass() {
  29. class Profile {
  30. String name;
  31. String email;
  32. String phone;
  33. List<String> occupation;
  34. List<String> language;
  35. List<String> hobby;
  36. }
  37.  
  38. Profile profile = new Profile() {
  39. {
  40. name = "John Lennon";
  41. email = "foobar@gmail.com";
  42. phone = "+81-90-0000-0000";
  43. occupation = Arrays.asList("Programmer", "System Engineer");
  44. language = Arrays.asList("Japanese", "English", "Spanish", "Chinease");
  45. hobby = Arrays.asList("Photography", "Traveling", "Fishing", "Onsen");
  46. }
  47. };
  48.  
  49. System.out.println(profile.name);
  50. System.out.println(String.join("\n", profile.occupation));
  51. }
  52.  
  53. public static void main (String[] args) throws java.lang.Exception
  54. {
  55. // your code goes here
  56. new Ideone().doHashMap();
  57. new Ideone().doClass();
  58. }
  59. }
Success #stdin #stdout 0.05s 320576KB
stdin
Standard input is empty
stdout
John Lennon
Programmer
System Engineer
John Lennon
Programmer
System Engineer