Hey All!
I am a newbie in Java but have come across a problem I can't really grasp.
If you can, please enlighten me, as my head got stuck on this issue
Alright: assume an ArrayList with objects of class Employee which all have names, id's and salaries. Problem - find the minimum salary.
So, I understand that I need to create a for loop, but here's where things become tricky. I have no problem of finding min/max of INT in Arrays, or longest/shortest strings in ArrayLists, and even max salary in this ArrayList (i.e. for loops).
I do not want to use Collections or similar methods - so where do I do it wrong?
Example:
int lowest = ArrayList.size(); for(Employee s:ArrayList){ if(s.getSalary()<lowest){ lowest = s.getSalary(); } }
? - lowest becomes ArrayList.size(), but not the smallest salary.