0

The result should be like [1,2,3,4], but i get garbled result like this

[com.test.db.Network@383c7b61, com.test.db.Network@7f87898,
 com.test.db.Network@6b93f47a, com.test.db.Network@50fb09cc]

Below is my related class

private static void doLocationList(PrintWriter responseOut) throws Exception
{
//---testing show network ID list
int x=0;
Network network = new Network();
responseOut.println("this is I: " +network.getNetworkID(x));

......
}

This is from another class

public static List<Network> getNetworkID(int networkID) throws Exception
{
List<Network> idList = new ArrayList<Network>();
Connection conn = getConnection();
PreparedStatement Statement = conn.prepareStatement("Select id from network");
ResultSet result = Statement.executeQuery();
    while(result.next()) {
        Network network = new Network();
        network.setId(result.getInt("id"));
        idList.add(network);
    }

return idList;
}

Any idea? Please help.

Ravinder Reddy
  • 23,692
  • 6
  • 52
  • 82
Lc Wei
  • 69
  • 9

1 Answers1

1

If you want to print the list of objects directly, you need to override the toString() method in the Network class and specify how to print the values when an object of this class is printed directly.

The default toString() method is as shown in Object class docs. Have a look at this post about toString()

Community
  • 1
  • 1
anirudh
  • 4,116
  • 2
  • 20
  • 35