This site requires JavaScript, please enable it in your browser!
Greenfoot back
DukeFutzwillus
DukeFutzwillus wrote ...

2016/11/28

Is there a way to count objects of a specific Class, or even multiple classes?

DukeFutzwillus DukeFutzwillus

2016/11/28

#
I have been trying to use the getObjects().length(); I saw this being used somewhere and thought it was possible but I am unable to get it to work. Is there a way to count objects in of just one class?
danpost danpost

2016/11/28

#
DukeFutzwillus wrote...
I have been trying to use the getObjects().length(); I saw this being used somewhere and thought it was possible but I am unable to get it to work. Is there a way to count objects in of just one class?
First, the 'getObjects' method needs a class or null for a parameter; second, it returns a List object and there is no 'length' method that can be used on a List object. It does have a 'size' method, so you could do this:
1
int actorCount = getObjects(Actor.class).size();
You can replace 'Actor' with the name of any subclass of Actor to be more specific.
DukeFutzwillus DukeFutzwillus

2016/11/28

#
Thank you very much I wanted to use the .size but didn't know it.
You need to login to post a reply.