Tor Ludgivsen wrote:Hello! Im having a problem with my library system...
1. For future reference, try to only post code that is relevant to your problem; it saves us from having to plough through a lot of irrelevant information and will help you get answers quicker.
And since Greg's already shown you your actual error, here are a few general tips:
2. Don't use Strings for anything except strings of characters; and the only field in your Person class that meets that criterium is name. For more information, see this page.
3. Avoid using single-character names for anything except loop variables. For example:
int a = personm.size(); Why not:
int size = personm.size(); (or the equivalent in Norwegian)?
Anything you can do to make your programs more readable is a good thing.
4. Your sort method is a good example of overthinking (and don't worry; it's a common beginner's mistake ):
First: Lists are usually better than arrays; and you can create a List directly from a Collection.
Second: You can sort an ArrayList just as quickly with Collections.sort() as you can an array with Arrays.sort().
Third: You can sort objects any way you like with a Comparator (java.util.Comparator). If you haven't heard about them yet, I suggest you read up on them.
Fourth: Get into the habit of using for-each loops. They save you all that mucking about with Iterators.
Put that all together and you get something like:
Isn't it funny how there's always time and money enough to do it WRONG?
Greg Charles thanks a lot. and i did look at it, but did not know that it matters the order i put data in.
Winston Gutkowski. thanks a lot, will follow your advices and try the new stuff you told me. is there some place on the forum where you can post your product, and just get advices on how to improve things?