• 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:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

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: 23588
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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!