package facadeTest.mapAndObject; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; /** * 将map放到list中,找出指定的value值在那个map中 Object可以强转成map * */ public class MapAndObjectChange { public static void main(String[] args) { Map<String, Object> map = new HashMap<String, Object>(); Map<String, Object> map01 = new HashMap<String, Object>(); Map<String, Object> map02 = new HashMap<String, Object>(); List<Map<String, Object>> list = new ArrayList<Map<String, Object>>(); List<Map<String, Object>> list01 = new ArrayList<Map<String, Object>>(); map.put("1", "fds"); map.put("2", "valu"); map01.put("3", "a"); map01.put("4", "b"); list.add(map); list.add(map01); // Object可以强转成map for (Object object : list) { map02 = (Map<String, Object>) object; String value = (String) map02.get("3"); if ("a".equals(value)) { list01.add(map02); } } System.out.println(list01); } }