File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Comparing two Strings Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Comparing two Strings " Watch "Comparing two Strings " New topic
Author

Comparing two Strings

Vidya Gupta
Ranch Hand

Joined: Mar 18, 2012
Posts: 98

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

Joined: Mar 17, 2011
Posts: 8427
    
  23

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

Have a look at String.compareTo().

Winston


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19073
    
  40

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


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Comparing two Strings