Reputation: 51
I have the code (see below), which counts agents ("developers") in a specific state. This works just fine.
Now I do not want to count agents in a specific state, but agents of a specific type only. How can I alter the code (or write some new code) to achieve this?
Thank you very much!
return this.getConnections()
.stream()
.filter(Developer -> Developer.inState(WantA))
.count();
Upvotes: 0
Views: 143
Reputation: 135
You can check object type in Java by using the instanceof
keyword.
return this.getConnections()
.stream()
.filter(obj -> obj instanceof ClassName)
.count();
Upvotes: 1