• Post Reply Bookmark Topic Watch Topic
  • New Topic

ArrayList of Boolean  RSS feed

 
Hernan Tavella
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, i have this trouble, how can i do to improve this code, so i can verify that all the elements in the arraylist are true. Thanks!

 
Paul Clapham
Sheriff
Posts: 22819
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right now you set the variable to "true" if any of the ArrayList entries are true. But you want it to be "true" if all of them are true.

Or to put it another way, you want the variable to be "false" if any of the ArrayList entries are false. You already know how to write the "any-of" code, so just adapt what you have there already.
 
Hernan Tavella
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is the solution that i could find, perhaps there another better but it works..

 
Hernan Tavella
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i thought this solution because always the last cell is evaluated and the other no matter what they have, but with the listsize i can see how many elements are so at the end of the code i can evaluate it.
 
Paul Clapham
Sheriff
Posts: 22819
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or if you follow the suggestion which I made:

 
Hernan Tavella
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, your suggest is much better and simple. i justed test it. thank you for helping me.
 
Tony Docherty
Bartender
Posts: 3271
82
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could also add a break statement after you have found a 'false' as there is no need to check the rest of the values in the list once you have found your first false value.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or you could just let the API do all the work for you
 
Hernan Tavella
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, i didnt know that api, is very usufull, can it work with Strings too?? ej, verify is all text box are full. Thank you Neal.
 
Tony Docherty
Bartender
Posts: 3271
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All the methods in the collections classes will work with whichever object type you put in them, so if your list contains String objects then calling .contains("MyString") will return true if there is at least one String object in the list whose equals() method returns true when passed the String "MyString".

Thank you Neal.

It's generally best to refer to western people by their first name ie Joanne unless using a title such Ms Neal (which is a little too formal for a forum).
 
Hernan Tavella
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It works great this API, much less code and simple, thank you Docherty!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!