list.removeIf(this::isAllNull);
private Boolean isAllNull(Object obj){
boolean isNull = true;
Map<String,Method> methodMap = getObjectGetterMethod(obj.getClass());
for (Map.Entry<String,Method> entry: methodMap.entrySet()){
Method method = methodMap.get(entry.getKey());
try {
Object value = method.invoke(obj);
if (value != null && !"".equals(value)){
isNull = false;
}
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
}
return isNull;
}
private static Map<String, Method> getObjectGetterMethod(Class object) {
Field[] fields = object.getDeclaredFields();
Method[] methods = object.getDeclaredMethods();
Map<String, Method> methodMap = new HashMap<>();
for (Field field : fields) {
String attri = field.getName();
for (Method method : methods) {
String meth = method.getName();
if (meth != null && "get".equals(meth.substring(0, 3)) &&
Modifier.isPublic(method.getModifiers()) &&
("get" + Character.toUpperCase(attri.charAt(0)) + attri.substring(1)).equals(meth)) {
methodMap.put(attri, method);
break;
}
}
}
return methodMap;
}