import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
public class PrintObjectList {
public static void printList(List list) {
if (list == null || list.size() == 0)
return;
for (Object o : list) {
if (o != null){
Field[] fields = o.getClass().getDeclaredFields();
try {
for (Field f : fields) {
f.setAccessible(true);
String name = f.getName();
Object value = f.get(o);
System.out.println(name + "--" + value.toString());
}
} catch (IllegalAccessException e) {
}
}
}
}
public static void main(String args[]){
List list = new ArrayList();
list.add(new Example(0, "aa"));
list.add(new Example(1, "bb"));
list.add(new Example(2, "cc"));
list.add(new Example(3, "dd"));
printList(list);
}
}
class Example{
private int i;
private String s;
public Example(int i, String s){
this.i = i;
this.s = s;
}
public int getI() {
return i;
}
public void setI(int i) {
this.i = i;
}
public String getS() {
return s;
}
public void setS(String s) {
this.s = s;
}
}