Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

strange result

 
Hung Tang
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone explain why the following code evaluates to false?
package suncertify.db;
import java.io.*;
public class Test {
public static void main (String[] args) throws
IOException, Database Exception {
Data d = new Data("db.db");

DataInfo di = d.find("BA003"); //record 23
String[] values = di.getValues();
System.out.println(values[3]); //result is "BeethAir"
System.out.println(values[3].equals("BeethAir")); //result is false??

}
}
 
Rowan Brownlee
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may have some spaces at the end of "BeethAir ". Following prints out false.
Eg.
 
Hung Tang
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've checked the code many times, there are no spaces. Both are value[3] and "BeethAir" are strings, so the equals() method should return true. It's very puzzling, I want to fix this problem so I can continue to revamp my criteriaFind() method.
 
Siddharth Mehrotra
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Hung ,
there are spaces in some data that we get from the mtheods of data class
try using trim comand
System.out.println( (values[3].trim()).equals("BeethAir"));
thsi might return true.
and if want to test if there were any spaces in the data returned u can see that with the following statement
System.out.println(values[3].length())

I hope that solves your problem
 
Hung Tang
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Siddharth, it works! thanks a lot!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic