I am struggling with this basic code below ,
how do i prevent the last comma “,” from being appended to the String.
String outScopeActiveRegionCode="";
List<String> activePersons=new ArrayList<String>();
HashSet<String> outScopeActiveRegionCodeSet=new HashSet<String>();
for (String person : activePersons) {
outScopeActiveRegionCodeSet.add(person);
}
Iterator itr = outScopeActiveRegionCodeSet.iterator();
while(itr.hasNext()){
outScopeActiveRegionCode+=itr.next();
outScopeActiveRegionCode+=",";
}
Id actually do it the other way around, id append the comma before on all cases except the first, its easier.
The reason for this is that it is much simpler to detect the first case than the last case.