I am creating a method to add to an ArrayList which contains person objects, which has a name, address and age. It should order them from lowest to highest. Mine only works for if it does not end up in last place or is not empty, how can I write my code differently?
public void addAgeSorted(Person p){
 int a = 0;
 while(p.getAge() >= this.plist.get(a).getAge() ){
  a++;
  }
 this.plist.add(a,p);
}
 
     
     
     
     
     
    