0

Hey I am working on a project that enters in information for departments. This information includes, name, abbreviation, location, and number of members.

The first class I have accepts 8 parameters, (string, string abbrev, string, int, int, int, int, int, double).

It's added into an ArrayList and I'm having trouble testing to see if a string abbrev exists in any of those classes.

What I have as a method is:

  private ArrayList<DeptInfo> dept = new ArrayList<DeptInfo>(); 

  public boolean deleteDeptInfo(String abbrev) {

  boolean result = false;
  int index = -1;
  for (DeptInfo test : dept) {
     if (test.getAbbrev() == abbrev) {
        index = dept.indexOf(test);
        break;
     }
  }

  if (index >= 0) {
     dept.remove(index);
     result = true;
  }
  return result;
}

1 Answers1

0

i bet its at the if condition argument, when you compare strings you have to use .equal method.

JungJoo
  • 171
  • 1
  • 2
  • 10