• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Having problem when i sort out data from hashmap. Variables are mixing!

 
Greenhorn
Posts: 7
Python Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello! Im having a problem with my library system.

the p.name and p.isbn are mixing up.



Full kode:
 
Sheriff
Posts: 3063
12
Mac IntelliJ IDE Python VI Editor Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This might be the problem:



and


It's always good to check the obvious stuff first!
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tor Ludgivsen wrote:Hello! Im having a problem with my library system...


Tor,

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:
HIH

Winston
 
Tor Ludgivsen
Greenhorn
Posts: 7
Python Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Marshal
Posts: 79234
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tor Ludgivsen wrote: . . . is there some place on the forum where you can post your product, and just get advices on how to improve things?

Yes. Here
 
reply
    Bookmark Topic Watch Topic
  • New Topic