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++ - llvm function pass ReplaceInstWithInst malloc -

java.lang.NoClassDefFoundError When Creating New Android Project -

Decoding a Python 2 `tempfile` with python-future -