Java tutorial
//package com.java2s; //License from project: Apache License import java.lang.reflect.Field; import java.util.HashMap; import java.util.Map; public class Main { public static Map<String, String> compareMap(Map<String, String> map, Object obj) { Map<String, String> mapValue = new HashMap<String, String>(); Field[] fields = obj.getClass().getDeclaredFields(); for (Field field : fields) { String name = field.getName(); if (map.containsKey(name)) { mapValue.put(name, map.get(name)); } } return mapValue; } }