Win a copy of AWS Security this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

strange result

 
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??

}
}
 
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.
 
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!
 
Can't .... do .... plaid .... So I did this tiny ad instead:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic