I want show the content of my java object in eclipse console, just like debugging in chrome, and show JavaScript object in chrome console use the console.dir();
2 Answers
Run your code with a debugger, and watch whatever object you need to.
2 Comments
lovespring
this is what I know, is there any simple way to dump the object in console ?
Eran
@lovespring Dump what object? Your program probably has multiple objects. And when do you want to dump it? You usually examine the contents of your objects when running your program in a debugger. This way you can view whatever object you wish, whenever you pause the execution of the program.
Just Ovveride the toString() method of your Object and construct your String there in whichever format you like, For ex
@Override
public String toString() {
return "Objname{" + "property1=" + value1+ ",
prop2=" + val2+ ",
prop3=" + val3+ '}';
}
then simply
System.out.println(object.toString());