I'm trying to get the following code to work, but it fails in the last section. When I try to access the list through the iterator it returns an array of Strings, but I'm unable for figure out the syntax to get the elements of the array. I've tried various ways of accessing them and different casts but none have worked. The more I change it, the worse it gets. Maybe the problem is built into the design I used? Any suggestions would be very appreciated.
Larry Krigbaum wrote:Maybe the problem is built into the design I used?
I'd say that's part of it. The 2D array is icky. It would make more sense to define a Name class with first, middle, and last fields, and an override of the toString() method.
After you get it working that way, it may be worth coming back to this approach to see if you can get it working both for comparison of the approaches and to brush up whatever are of Java is keeping you from getting it working now.
Joined: Oct 25, 2002
Thanks for the suggestions. I'm trying to see if I can implement them. I think the best approach may well be to just implement my own linked list specific to the data I'm working with. I really like the idea of using generic Java collections, but they never seem to be very useful for most applications. Thanks again.
Larry Krigbaum wrote:I think the best approach may well be to just implement my own linked list specific to the data I'm working with.
No, that would be a lot of work for no reason.
I really like the idea of using generic Java collections, but they never seem to be very useful for most applications.
Then you don't yet understand how to use them correctly. They work very well for very, very many situations. Your case here is very simple and straightforward and common. You were given suggestions for two different approaches, either one of which will give you the results you want very simply, without needing to implement your own list. I've been programming with Java full time for 15 years and I have never once needed to implement my own collection.