It is necessary to display all the values of HashMap hmap for the Group key. But an empty hmap is passed to the method. Displays null. How to transfer to a method the filled HashMap hmap?
public class ListGroup { static Map<Group, ArrayList<People>> hmap; @Override public String toString() { return "ListGroup [hmap=" + hmap + "]"; } public Map<Group, ArrayList<People>> getHmap() { return hmap; } public void setHmap(Map<Group, ArrayList<People>> hmap) { this.hmap = hmap; } public ListGroup(Map<Group, ArrayList<People>> hmap) { super(); this.hmap = hmap; } public ListGroup() { super(); } public static Map<Group, ArrayList<People>> somm() { ArrayList<People> people1 = new ArrayList<>(); people1.add(new People(85, 170, "Gava", "Ivan", true)); people1.add(new People(120, 180, "Nazumo", "Petro", false)); people1.add(new People(95, 167, "Dorod", "Marija", true)); people1.add(new People(69, 170, "Omaee", "Vova", true)); Map<Group, ArrayList<People>> hmap = new HashMap<>(); hmap.put(new Group("The Best"), people1); return hmap; } public static void frak(Map<Group, ArrayList<People>> hmap) { Set<Entry<Group, ArrayList<People>>> entries = hmap.entrySet(); for (Iterator<Entry<Group, ArrayList<People>>> iterator = entries.iterator(); iterator.hasNext();) { Entry<Group, ArrayList<People>> entry = iterator.next(); if (entry.getKey().getName().equals("The Best")) { for (Iterator<People> i = entry.getValue().iterator(); i.hasNext();) { System.out.println(entry); break; } } } } public static void main(String[] args) { System.out.println(hmap); frak(hmap); } }