java - how to use Iterator in object arraylist -


here got

public class planet {      arraylist<person> person  = new arraylist<>();     iterator<person> itr = person.iterator();      public string getfemalename()     {          (int = 0;a < person.size();a++)         {             if (person.getgender == "female")             {                 return person.get(a).getname();             }         }     } } 

now i'm having 2 problems, 1st want return female's name,but seems have return there no female in arraylist. 2nd how use iterator instead of using loop.

  1. for case when no female present , putting return null in end of function job, because first return statement won't executed @ all.

  2. for second question, using iterator .. replace for loop

    while(itr.hasnext()) { person newperson=itr.next(); if(newperson.getgender().equals("female") return newperson.getname(); }


Comments

Popular posts from this blog

c - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -