Win a copy of Machine Learning Systems: Designs that scale this week in the Scala forum
or Xamarin in Action: Creating native cross-platform mobile apps in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Comparing two Strings  RSS feed

 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi,

In my example, am having a double value and am typecasting that to a string. Now i want to compare that string with some inters.

That is,
Double myDouble=10.2;
String str=String.valueOf(myDouble);

int i=20,j=50;
Sring s=Integer.toString(i);
String st=Integer.toString(j);

Now i want to compare the 'str' variable like this,

if(str>i)

some work;

if(str>j)

some work here;


How can i do this,

it is not allowing me to use greater than operator. Please suggest me..



 
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Vidya Gupta wrote:it is not allowing me to use greater than operator. Please suggest me..


Have a look at String.compareTo().

Winston
 
author
Sheriff
Posts: 23507
138
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Winston Gutkowski wrote:

Vidya Gupta wrote:it is not allowing me to use greater than operator. Please suggest me..


Have a look at String.compareTo().



Yes, but keep in mind, that it will be compared like strings and *not* like integers. This means that "5" comes after "1000".

Henry
 
If you try to please everybody, your progress is limited by the noisiest fool. And this tiny ad:
Rocket Oven Kickstarter - from the trailboss
https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!