File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

comparing System.getProperty to string

Mike Harris

Joined: Oct 13, 2005
Posts: 5
I'm trying to test whether the os is Windows XP by using the"") 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

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
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.


Java API Documentation
The Java Tutorial
I agree. Here's the link:
subject: comparing System.getProperty to string
It's not a secret anymore!