Page 1 of 1

ArrayList to check

Posted: Wed Feb 18, 2015 2:47 am
by Bencratus
Hello,

e.g. character have these buffs in arraylist which will be added if he press button x,a,b etc.

List <Integer> _buffs = new ArrayList<>();

_buffs.add(100);
_buffs.add(101);
_buffs.add(102);

how to check how much he have buffs which ids are 101 and 102?
because if _buffs.size(); it will returns all hes buffs count, but I need only e.g. 101 and 102.
also _buffs.contains don't need for me, because it is boolean, I need int...

Thanks,
Bencratus

Re: ArrayList to check

Posted: Wed Feb 18, 2015 9:21 am
by Zealar
Replace list with map ;)

Re: ArrayList to check

Posted: Wed Feb 18, 2015 10:39 am
by Sdw
Difficult to know what you are really doing so I'm just going to give you what you wanted

long buffCount = _buffs.stream().filter(b -> (b == 101 || b == 102)).count();

Re: ArrayList to check

Posted: Wed Feb 18, 2015 1:20 pm
by Bencratus
Zealar wrote:Replace list with map ;)
Thanks, helped :)
Sdw wrote:Difficult to know what you are really doing so I'm just going to give you what you wanted

long buffCount = _buffs.stream().filter(b -> (b == 101 || b == 102)).count();
Thanks, but your method for me hardcoded if I want to use more buffs not only these 2 ;)