Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

print method in java

Tags:

java

I want to ask you about the print vector array , the following one:

Vector[] routingTable = new Vector[connectivity.length];

I tried this method , but it doesn't work with me and it gives me protocol.Route@c17164 when I printed in the main, here is the code, so can you tell me why it doesn't print the correct value ?

public String printRT(int hop)
{
   String s = "";
   for (int i = 0; i < conf.routingTable[hop].size(); i++) 
  {
     s= " ROUTING TABLE " + conf.routingTable[hop].get(i);
  }
  return s;
}

2 Answers

it looks like you need to implement the toString() method in protocol.Route.

class Route {
    public String toString() {
         return "some string that makes sense";
    }
}
like image 151
Cogsy Avatar answered Aug 22 '26 18:08

Cogsy


Either override the toString() method on the protocol.Route class, or get the desired properties from the Route object and append them to the String s inside your printRT method.

like image 42
erickson Avatar answered Aug 22 '26 18:08

erickson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!