File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Comparing two Strings

 
Vidya Gupta
Ranch Hand
Posts: 98
  • 0
  • 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..



 
Winston Gutkowski
Bartender
Pie
Posts: 9477
50
Eclipse IDE Hibernate Ubuntu
  • 0
  • 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
 
Henry Wong
author
Marshal
Pie
Posts: 20836
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic