Java tutorial
//package com.java2s; import java.lang.reflect.Method; public class Main { public static boolean setProperty(Object object, String fieldName, Object fieldValue) { Class<?> clazz = object.getClass(); String mname = "set" + fieldName; try { for (Method m : clazz.getMethods()) { if (m.getName().equalsIgnoreCase(mname)) { m.invoke(object, fieldValue); return true; } } } catch (Exception e) { throw new IllegalStateException(e); } return false; } }