Java tutorial
//package com.java2s; /* * This software is in the public domain under CC0 1.0 Universal plus a * Grant of Patent License. * * To the extent possible under law, the author(s) have dedicated all * copyright and related and neighboring rights to this software to the * public domain worldwide. This software is distributed without any * warranty. * * You should have received a copy of the CC0 Public Domain Dedication * along with this software (see the LICENSE.md file). If not, see * <http://creativecommons.org/publicdomain/zero/1.0/>. */ import java.util.*; public class Main { /** Find all values of a named field in a nested Map containing fields, Maps, and Collections of Maps (Lists, etc) */ public static void findAllFieldsNestedMap(String key, Map theMap, Set<Object> valueSet) { Object localValue = theMap.get(key); if (localValue != null) valueSet.add(localValue); for (Object value : theMap.values()) { if (value instanceof Map) { findAllFieldsNestedMap(key, (Map) value, valueSet); } else if (value instanceof Collection) { // only look in Collections of Maps for (Object colValue : (Collection) value) { if (colValue instanceof Map) findAllFieldsNestedMap(key, (Map) colValue, valueSet); } } } } }