This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
The only way I could see this happening is if you were adding the same instance of the record class to the Map 31 times. So each time you think you are creating a new record, you are actually updating the single instance with the information from the record you have just read from the data file. From your code snippet, it doesn't appear that you are doing this.
I'd suggest using the debugger in your IDE (assuming you are using one!) and see exactly what is happening when the second record gets created - does the information in the first record get changed? Then see what happens when you add the second record to the Map.
SCJP (1.4 | 5.0), OCJP (6.0), OCMJD
Joined: Jul 17, 2011
Sean Keane wrote:I'd suggest using the debugger in your IDE (assuming you are using one!) and see exactly what is happening when the second record gets created - does the information in the first record get changed?
yes of cos I use the eclipse debugger.
all the information in the records get change.. they only have different IDs
Ixus See wrote:all the information in the records get change.. they only have different IDs
I'm guessing English is not your first language ? But it's worth keeping in mind that it makes it harder for people to understand your problem if you don't describe it in more detail. One line statements make it very hard to understand what your problem is. The more effort you put into your posts, the more likely someone will read it and the more likelihood of a positive response.
From the sounds of it you are saying that when the second object (record) gets created the information in the first object changes. If my understanding is correct, then you are not creating a new object each time you are creating a new record. You are simply reusing the one single object. If that is the case, then I don't think anyone here will be able to help you - because we can't see your code. You need to do the job of a developer , debug through your code and find out where the problem is.