Removing Item from Array List

Posted on 2005-03-14
Medium Priority
Last Modified: 2010-03-31

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);


Question by:jmc430
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 86

Accepted Solution

CEHJ earned 2000 total points
ID: 13539645
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();

Author Comment

ID: 13559281
thanks CEHJ!

LVL 86

Expert Comment

ID: 13560622

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Suggested Courses
Course of the Month13 days, 4 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question