Hi guys, I'm having trouble printing an ArrayList of Employees(My objects) for school. It keeps printing out what I think to be the hexcodes for various characters. I tried many variants of google searches but none of the answers that came up seemed to help.

What you're seeing is the output from Object.toString() - read the API documentation for the method, and then override it in your own classes. Writing toString() methods for my classes is one of my favourite Java programming activities: it's like putting the cherry on the cake.

Glancing at your code again, you may have more problems than that. If you have a list of Employee, or even a list of lists of Employee, all you should need to do is to implement Employee.toString() and then:

List.toString will iterate over its members invoking toString() on each, concatenate all the return values nicely and return it.

March 2nd, 2012, 11:06 AM

er1111

Re: Printing an ArrayList of user-defined Objects

Hi there! I did have a.toString() method, but I found that I needed the original.toString() method from Arrays.toString(), so I ended up just calling my .tostring() method printerstring.

For some reason when i called Arrays.toString() while my Employee.toString() method existed, it produced a different result, like I had somehow edited Arrays.toString() by creating Employee.toString(). I changed my Employee.toString() method to Employee.printerString();

-EDIT-
typos

-EDIT 2-
I ended up just messing around with my loadEmployees() method and my Employee.create method, cleaned it up and it ended up working. Here is the (semi-)finished code: