I'm new to java and I'm having a problem with ArrayList
. I want to get the highest value from Jozef and Klaus.
ArrayList
looks like:
| Name | Age|
+--------------+----+
| Jozef Coin | 55 |
| Jozef Coin | 56 |
| Jozef Coin | 57 |
| Klaus Neumer | 34 |
| Klaus Neumer | 31 |
| Klaus Neumer | 59 |
This is my code so far, it only returns the highest value in the arraylist
.
Person b = persons.get(0)
for(Person p: persons){
if(p.getAge() >= b.getAge()){
b = p;
System.out.println(b.toString());
}
}
I'm probably way over my head but I'd love to know if this is possible and if so there is an solution to this.