Removing Item from Array List


I'm having some trouble with my code .. I am trying to suppress the repetitions of a department name in an array list.

I am setting a boolean within the if statement, to set isDUPLICATE=false when deps.equals(depL.departmentName())

However, whenever I set the boolean, it sets it for the entire function, rather than just within the if statement ..

Basically, I would like it to only be set for the conditional when the criteria is met .. and I want the boolean to be reset to true afterwards (in order to show the rest of the list of depts).  I have NSLOg.out.appendln(Printf) statements everywhere showing the correct boolean values, but for some reason all the values being returned on my HTML page are all either true or false, instead of set as particular to the values in my printf statements.

Please help!  

This is my relevant code:

public NSArray getAllDepartments(){

   if (results.count()==2){
    Department depFirst = (Department)a.objectAtIndex(0);
    Department depLast = (Department).b.objectAtIndex(1);

   if (!(depFirst .divisionName().equals(depLast .divisionName())){
    if((deps!=null)&&(deps.equals(depLast .departmentName())){


   NSArray originalListWithDuplicates=ms.allObjects();
   EOSortOrdering ordering1=new EOSortOrdering("departmentName", EOSortOrdering.CompareAscending);
   NSMutableArray sortOrdering=new NSMutableArray();
   return EOSortOrdering.sortedArrayUsingKeyOrderArray(originalListWithDuplicates,sortOrdering);


Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

CEHJConnect With a Mentor Commented:
You could wrap the Department object and then create a Set of the wrappers. This will eliminate duplicates automatically:

public class DepartmentNoDuplicatesWrapper {
      private Department department;
      public DepartmentNoDuplicatesWrapper(Department department) {
            this.department = department;
      public boolean equals(Object o) {
            Department otherDepartment = (Department)o;
            return department.getName().equals(otherDepartment.getName());
      public int hashCode() {
            return department.getName().hashCode();
jmc430Author Commented:
thanks CEHJ!

All Courses

From novice to tech pro — start learning today.