aspose file tools*
The moose likes Beginning Java and the fly likes How I can compare an arraylists values in order? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How I can compare an arraylists values in order?" Watch "How I can compare an arraylists values in order?" New topic
Author

How I can compare an arraylists values in order?

D Hagy
Greenhorn

Joined: Jul 05, 2011
Posts: 12
I need to have two arraylists. I declared them. I declared a "mine" arraylist and an "user" arraylist with this code:



I want to store in these values, what are will be important to contact with the user:
I added values to my mine arraylist:


I want to add a values to the user named arraylist if the user press a button. So I added this code:

and
to an another button.

I added two line to the buttons so I can follow how the arraylist looks like in the appropriate moments.

Then if the user clicks an another button, I want to compare these lists, so I implemented the following code:


If the two arraylists are the same in the order and in values, I want to show a new screen (its name is for example good), and if not I want to show an another( its name is for example lose). But I have a problem. My program is only show my lose screen if the user only clicked the button which add 1 to the arraylists, or if he/she only clicked the button which add 0 to the arraylist. How can I make my program to run as I want? Thanks in advance
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5845
    
    7

Have your tried stepping through the for loops to see what is going on? With only 3 values in the arrays (for your example), you should be able to desk-check the loops and immediately see what the problem is. Actually, you don't even have to go very far: the first time through the outer loop, you go through the inner loop 3 times. The first time is ok, but what happens the second time through the inner loop?

That should be enough of a hint. But let us know if you still don't see it.


JBoss In Action
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40029
    
  28
Why are you using the == operator on a reference type? That almost always gives the wrong result.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How I can compare an arraylists values in order?