package facadeTest.mapAndObject; import java.util.ArrayList; import java.util.List; /** * * 将对象放入到map中,找出map中指定的某个属性值并放在一个list中 */ public class TargetAndMapChange { public static void main(String[] args) { Safc safc = new Safc(); safc.setAccident("意外险"); safc.setProperties("财产险"); safc.setForce("商业险"); Safc safc01 = new Safc(); safc01.setAccident("意外险01"); safc01.setProperties("财产险01"); safc01.setForce("商业险01"); // Map<String,Object> map = new HashMap<String,Object>(); List<Safc> list = new ArrayList<Safc>(); List<String> list01 = new ArrayList<String>(); list.add(safc); list.add(safc01); System.out.println(list); for (Safc safc02 : list) { // 对象不能强转成map,直接get出key对应的value的值 // map = (Map<String, Object>) safc02; String value = safc02.getProperties(); System.out.println(value); if ("财产险".equals(value)) { list01.add(value); } } System.out.println(list01); } }
package facadeTest.mapAndObject; /** * 险种实体类 * */ public class Safc { private String accident; private String properties; private String force; public String getAccident() { return accident; } public void setAccident(String accident) { this.accident = accident; } public String getProperties() { return properties; } public void setProperties(String properties) { this.properties = properties; } public String getForce() { return force; } public void setForce(String force) { this.force = force; } @Override public String toString() { return "Safc [accident=" + accident + ", properties=" + properties + ", force=" + force + "]"; } }