0

OK. Im reading all the objects from an arraylist and grabbing thier names.

            for(Contractor o : fa.allValues){
                System.out.println(o.getName());
            }

This returns

Bobs Tools
                //The problem
Ic Remodeling
Fred and Nobby
Dogs With Tools
Dogs With Tools
Bitter Homes and Gardens
Etc etc

Now....when i create and add an object, i want to put the new object in any empty spaces that it finds. It should find an empty space when it comes to the 2nd record.

However........

String str = allValues.get(1).getName(); // where 1 is the location of the empty record

all the following returns false

System.out.println(str == "");
System.out.println(str == " ");
System.out.println(str == null);

I want to input a condition that returns true. What basic issue have i over looked here?

ragingbull
  • 119
  • 1
  • 2
  • 8

2 Answers2

2

use equals for testing equality of string and not ==

Eugene
  • 117,005
  • 15
  • 201
  • 306
1

Your equality for an empty string is wrong. In java you should compare it using the equals-method.

I would recommend using the apache commons lang StringUtils.isEmpty() method.

Kurt Du Bois
  • 7,550
  • 4
  • 25
  • 33