• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

a command line argument, a comparison, an interesting result

 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The following program compiles

I ran the program with the command "java StringTest /?" at the DOS prompt
The output was:
false
/?
/?
Can someone explain this?
I want to know if a user uses the program with the parameter /?
 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try s.equals("/?") in place of s=="/?".
The "==" operator tests if the two object references point to the same object, which is not true in this case.
String class overrides the "equals" method in the Object class,
to compare the values of the two strings in question and return true if they are the same. It DOES NOT check to see if both the strings point to the same object in memory.
 
Carlos Failde
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah yes of course. Much thanks
reply
    Bookmark Topic Watch Topic
  • New Topic