二、使用JAVA反射機制移除單個字符(返回刪除字符後的新對象)

/**
 * 
 * @ClassName: RemoveSingleChartUtil 
 * @Description: TODO(移除單個字符id工具類) 
 * @author 學渣要逆襲
 * @date 2017年7月6日 上午10:03:51 
 *
 */
public class RemoveSingleChartUtil {

	public static Object resultObj (String[] array, String compareId,Object obj,String objMethod) throws Exception{
		if (array.length == 1) {
			if (array[0].equals(compareId)) {
				array = (String[]) ArrayUtils.remove(array, 0);
			}
		} else {
			for (int i = 0; i < array.length;) {
				if (array[i].equals(compareId)) {
					if (array.length >= 1) {
						array = (String[]) ArrayUtils.remove(array, i);
					}
					i = 0;
				} else {
					++i;
				}
			}
		}
		String handlMatterIds = StringUtils.join(array,",");
		Method method = obj.getClass().getDeclaredMethod(objMethod,String.class);
		method.invoke(obj, handlMatterIds);
		return obj;
	}
}
相關文章
相關標籤/搜索