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. Recipe r = new Recipe();
  13. r.addMapEntry("dish", new HashSet<>(Arrays.asList("a", "b")));
  14. System.out.println(r.recipes);
  15. }
  16. }
  17.  
  18. class Recipe {
  19. Map<String, Set<String>> recipes;
  20.  
  21. public Recipe() {
  22. this.recipes = new HashMap<>();
  23. }
  24.  
  25. public void addMapEntry(String dish, Set<String> ingredient){
  26. recipes.get(dish);
  27. if (recipes.containsKey(dish)) {
  28. recipes.replace(dish, ingredient);
  29. } else {
  30. recipes.put(dish, ingredient);
  31. }
  32. }
  33. }
Success #stdin #stdout 0.05s 2184192KB
stdin
Standard input is empty
stdout
{dish=[a, b]}