• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

String.equals

 
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What will be the result of compiling and running the following example?

I have no question. I am just trying to confuse someone.
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
o == c and o == "astring" also return true.
 
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can somebody explain to me what the Comparable interface or class is all about? I don't ever remember seeing it in my Sybex book, but I think I saw it in some mock exams.
 
Thomas Paul
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check the July 2002 issue of the javaRanch newsletter.
 
author
Posts: 8999
19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Marlene, et.al.,
It's the focus police again
Just for the sake of the new cowpokes here at JavaRanch, the Comparable interface is NOT on the SCJP exam.
Proceed with your wonderful exercise in confusion...
 
Ranch Hand
Posts: 867
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Marlene
oo...
I without using the compiler help me at this time
It is a good practice /exercise
Let me try......
boolean b1 = "astring".equals(o);
b1=true
boolean b2 = o.equals("astring");
b2=true
boolean b3 = "astring".equals(c);
b3=true
boolean b4 = c.equals("astring");
b4=true
boolean b5 = o.equals(c);
b5=true
boolean b6 = c.equals(o);
b6=true
boolean b7 = "astring".equals(s);
b7=false
boolean b8 = s.equals("astring");
b8=false
Because I seldom use Comparable
thanks for checking my answer
 
Thomas Paul
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are correct.
 
Or we might never have existed at all. Freaky. So we should cherish everything. Even this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
    Bookmark Topic Watch Topic
  • New Topic