wood burning stoves*
The moose likes Beginning Java and the fly likes comparing System.getProperty to string Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "comparing System.getProperty to string" Watch "comparing System.getProperty to string" New topic
Author

comparing System.getProperty to string

Mike Harris
Greenhorn

Joined: Oct 13, 2005
Posts: 5
I'm trying to test whether the os is Windows XP by using the system.property("os.name") compared to a string "Windows XP". It is not working and I cannot figure out why. Can anyone point me in the right direction. My code is:

marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Instead of comparing values (references) using ==, try String's equals method for a more meaningful comparison.

if(os.equals(cos)) {...


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
It looks like you need to read up on the difference between the equals() method and the == operator. This has been discussed many times on this forum, so you can use the Search Tool to find previous threads on the topic.

Layne


Java API Documentation
The Java Tutorial
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: comparing System.getProperty to string