wood burning stoves*
The moose likes Beginning Java and the fly likes contentEquals in java.lang.String Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "contentEquals in java.lang.String" Watch "contentEquals in java.lang.String" New topic
Author

contentEquals in java.lang.String

Vijay Raj
Ranch Hand

Joined: Oct 10, 2005
Posts: 110
Hello,

The String class in Java 5 has two contentEquals(), one that takes in a StringBuffer and another that takes in a CharSequence. contentEquals(CharSequence) was introduced in Java 5 AND StringBuffer IS-A CharSequence as in implements it.

Now, the question. Why do we need contentEquals(StringBuffer) in Java 5. Won't contentEquals(CharSequence) be enough.

One solution to this would be that programs written in Java 1.4 won't run in a Java 5 runtime if contentEquals(StringBuffer) is removed. But then, won't contentEquals(CharSequence) take its place.

regards,
vijay.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

The CharSequence version would take its place if you recompiled your code. But removing the method would break binary compatibility -- i.e., code that wasn't recompiled wouldn't work if it called the StringBuffer method.

To the best of my knowledge Sun has actually never removed a method from the API.


[Jess in Action][AskingGoodQuestions]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: contentEquals in java.lang.String
 
Similar Threads
how to compare two strings having first few letter common
How to Compare StringBuffer object with String Object
Guess the answer
This Weeks Giveaway:
setColor() method in the Graphics class