• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

strange result

 
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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??

}
}
 
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Siddharth, it works! thanks a lot!
 
The overall mission is to change the world. When you've done that, then you can read this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic