+ 3
Guys how can i print content of an object in java?
When I try to print it...it give some unexpected output like that..`` ObjectPassDemo@3 6ba f30c b1 = ob2: true DbjectPassDemo@77459877 b1 == ob3: false https://code.sololearn.com/crxqWlfA5851/?ref=app
6 ответов
+ 3
https://stackoverflow.com/questions/29140402/how-do-i-print-my-java-object-without-getting-sometype2f92e0f4
I figured this might help you.
+ 3
Override the toString() method inside your class. Use objectName.toString() to print.
Something like this-
public String toString() {
return "{"+a+","+b+"}";
}
+ 3
@Override
public String toString() {
return String.valueOf(this.a)+", "+String.valueOf(this.b);
}
Overriding the toString() method
+ 2
Marshall Thank you brother...it helped me to figure it out....
+ 2
Avinesh Thank you..^^
+ 1
Tushar kumar No worries, brother.