• Post Reply Bookmark Topic Watch Topic
  • New Topic

compair string value with integer value  RSS feed

 
aish sharma
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,


I am new to java , can anyone help me how to compair string value with integer??

Please see the below code...





but i am getting an error...please help me to solve this


Thanks
 
kunal acharya
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i think the problem is custid is string reference variable(for storing reference of string object) and you are comparing with string object"0".
use custid.equals("0") instead of custid=="0"
 
Bill Clar
Ranch Hand
Posts: 163
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you tell us what error you're receiving?
 
dennis deems
Ranch Hand
Posts: 808
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out the valueOf method in the Integer class. It might be cleaner to compare two integers than making the String comparison.
 
Anayonkar Shivalkar
Bartender
Posts: 1558
5
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello aish sharma,

Welcome to CodeRanch!

aish sharma wrote:but i am getting an error...please help me to solve this

Please, TellTheDetails - what error you are getting and what have you tried so far.

Secondly, do not ever use '==' operator for String comparison - unless you know what does it mean and if you really want that.
 
aish sharma
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI all,

Thanks for the help ...

I have tried the below code , i think its working ... not tested it yet completely.


 
BalaMurali dhar
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you tell me what error your getting?
 
Campbell Ritchie
Marshal
Posts: 56595
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can see the possible problem with that code that you will suffer an Exception if the String passed looks like "1.2" or anything else not an integer. Otherwise, it ought to work all right.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!