• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

comparing System.getProperty to string

 
Mike Harris
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Instead of comparing values (references) using ==, try String's equals method for a more meaningful comparison.

if(os.equals(cos)) {...
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic