1
I am having a problem with a java method. The intention is to split a Hashmap into pages, and return an Arraylist with each page.
Code:
    public static ArrayList<HashMap<String, Key>> getKeysMap(HashMap<String, Key> map, int maxItemsPerPage) {
    int pageItemAt = 0;
    int pageItemsTotal = 0;
    int mapTotal = map.size();
    HashMap<String, Key> page = new HashMap<>();
    ArrayList<HashMap<String, Key>> pages = new ArrayList<>();
    for(Map.Entry<String, Key> entries : map.entrySet()) {
        System.out.print("  DEBUG:: " + entries.getKey() + " " + entries.getValue() + " " + pageItemAt + " " + pageItemsTotal);
        page.put(entries.getKey(), entries.getValue());
        pageItemAt++;
        pageItemsTotal++;
        if(pageItemAt % maxItemsPerPage == 0 || pageItemsTotal == mapTotal) {
            pages.add(page);
            pageItemAt = 1;
            page.clear();
            System.out.println("-------------");
        }   
    }
    System.out.println(pages);
    for(int i = 0; i < pages.size(); i++) {
        System.out.println(pages.get(i));
    }
    return pages;
}
Debug:
