I want to do a simple implementation to do some operations based on a distinct Codes (aCode) among the bigCodeList contains duplicates. Below I have mentioned two approaches what i want to know is what is the more effective one among them in performance vice + memory consumption wise?
Approach 1 :
String tempStr = "";
for(String aCode : bigCodeList){
if(tempStr.indexOf(aCode) == -1) {
// deal With the aCode related work
tempStr += aCode+"-"
}
}
Approach 2 :
HashSet<String> tempHSet = new HashSet<String>();
for(String aCode : bigCodeList){
if(tempHSet.add(aCode)){
// deal With the aCode related work
}
}
Note : aCode is a Three Letter code like LON