I would like to compare String arrays to a list with market objects.
I implemented the code like that:
private List<Data> addMarketData(List<Data> list) {
String[] SEE = new String[]{"Albania", "Bosnia and Herzegovina", "Bulgaria", "Croatia", "Macedonia FYR", "Moldavia", "Montenegro", "Romania", "Serbia", "Slovenia" };
List<String> seeList = Arrays.asList(SEE);
String[] CEE = new String[]{"Czech Republic", "Hungary", "Poland", "Slovakia"};
List<String> ceeList = Arrays.asList(CEE);
for (int i = 0; i < list.size(); i++) {
for (int j = 0; j < seeList.size(); j++) {
if(list.get(i).getPropertyCountry().equals(seeList.get(j).toString())) {
list.get(i).setMarket("SEE");
}
}
for (int k = 0; k < ceeList.size(); k++) {
if(list.get(i).getPropertyCountry().equals(ceeList.get(k).toString())) {
list.get(i).setMarket("CEE");
}
}
}
return list;
}
However, I believe that this code produces more overhead than it really should. Especially the for loops. Could I just use one loop?
Therefore, how to make this piece of code much faster?
I appreciate your answer!