java - comparing 2 array list and loop through contents -
java - comparing 2 array list and loop through contents -
i retrieving elements 2 array lists , looping , comparing them. there improve way loop though this?. little slow , doesn't seem efficient
string name = employee.get(0).getempname(); for(int = 0; < employee.size(); i++) { if (name.equals(employee.get(i).getempname())) { (int j = 0; j < employer.size(); j++) { if (name.equals(employer.get(i).getempchoice()) && (employers.get(j).getcompchoice() == 1)) { if (!test.contains(name) || !test.contains(employers.get(j).getcompname())) { test += name + employers.get(j).getcompname() + "\n"; } } } } else { name = employees.get(i).getempname(); i--; } }
first of all, utilize foreach statements, easier on eyes
for(employee emp : employee)
also faster way utilize map store data. have iterate through 1 list.
map<string,employee> employees; for(employer emp : employer){ if(employees.get(emp.getempchoice()).getcompchoice() == 1){ //do stuff } }
depending on implementation of map
using may speed process. code more concise.
java arraylist
Comments
Post a Comment