Here you can find the source of removeEmptyLists(Map
public static void removeEmptyLists(Map<String, Object> map)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.Map; public class Main { public static void removeEmptyLists(Map<String, Object> map) { for (Iterator<Map.Entry<String, Object>> it = map.entrySet() .iterator(); it.hasNext();) { Map.Entry<String, Object> entry = it.next(); if (entry.getValue() == null) { it.remove();//w w w .ja v a 2s . c o m } else if (entry.getKey().equals("coordinates")) { // hack because schema for coordinates is inconsistent it.remove(); } else if (entry.getValue() instanceof List) { if (((ArrayList<?>) entry.getValue()).size() == 0) { it.remove(); } } else if (entry.getValue() instanceof Map) { if (((Map) entry.getValue()).size() == 0) { it.remove(); } else { removeEmptyLists((Map) entry.getValue()); if (((Map) entry.getValue()).size() == 0) { it.remove(); } } } } } }