• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How I can compare an arraylists values in order?

 
D Hagy
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Campbell Ritchie
Sheriff
Pie
Posts: 50171
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you using the == operator on a reference type? That almost always gives the wrong result.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic