5

I have 2 Object of the same String Buffer Class value. The string is equal () me...

 2 years ago
source link: https://www.codesd.com/item/i-have-2-object-of-the-same-string-buffer-class-value-the-string-is-equal-method-show-fake-result-why.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

I have 2 Object of the same String Buffer Class value. The string is equal () method Show Fake result Why?

advertisements
StringBuffer str1=new StringBuffer("hello1");
StringBuffer str2=new StringBuffer("hello1");
System.out.println(str1.equals(str2));

It will Showing False result Why?


StringBuffer equals() method isn't overridden to check content. It's using the default "shallow equals" that compares references it inherits from java.lang.Object.

StringBuffer str1=new StringBuffer("hello1");
StringBuffer str2=new StringBuffer("hello1");
System.out.println(str1.equals(str2));

is Comparing reference that is why you are getting false

Related Articles

Refer to a class, when we have an object of the same name

Please Note : This is an experiment, and not a real situation. I want to learn more, and hence I am asking this question. I have a class ABC, with a static method method(): public class ABC { public static void method(){ System.out.println("ABC class

A data structure based on the R-Tree: create new child nodes when a node is full, but what if I have many objects in the same exact position?

I realize my title is not very clear, but I am having trouble thinking of a better one. If anyone wants to correct it, please do. I'm developing a data structure for my 2 dimensional game with an infinite universe. The data structure is based on a si

Is it possible? Is it a good practice (to have an object in the same object)?

I am using nhibernate and have a table called tiers. A user makes in a form all the tiers they need. It could look like this Use Teir one up to $600 then use -- Use Teir two up to $1000 then use tier1 Use Tier three up to $1500 then use Tier 1 Use Ti

Can I have an object with the same name as the class in javascript?

Can I have object with the same name as class in javascript?There are no classes per se in javascript, only methods that build objects. To directly answer your question, yes and no. You can create a function that builds your object, but as soon as yo

Copy properties between objects using the reflection and extension method

This is my code where I create a "copy" of one object (Entity) into a custom object. It copies just properties with the same name in both source and target. My problem is when an Entity has a navgiaton to another Entity, for this case I added a

How to send a Struts action form object to the EJB session bean method?

I have Struts action form Object called register i need to send the action form object to a session bean method as parameter so I done the following public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, Http

Does the commutation instruction Java 7 with String use equal () method?

Java 7 supports switching with Strings like the code below switch (month.toLowerCase()) { case "january": monthNumber = 1; break; case "february": monthNumber = 2; break; default: monthNumber = 0; break; } Does Java call the equals() m

Passing the address of an object to the JNI and JNI method should populate the fields of that past object

I would like to pass the address of a java object and JNI method should populate the fields of the passed object. 1. The java code pass the given object reference. The JNI method should be able to cache this Object. This is one time call. 2. Then the

Jasmine test state of the object on the Ajax spy call method

I'm unit testing an Angular controller that uses a Rails Resource factory to handle GETing and POSTing model data from and to a Rails app. POSTing is done via a method on the model, e.g. (with a model $scope.resource): $scope.resource.update().then(s

What type of object does the Spring Hibernate Template method run for a count query on Oracle?

When run against and Oracle database, what is the runtime type of the object that the following Spring Hibernate Template (Spring 2.5 and Hibernate 3.3.2GA) code returns where the SQL query is a counting query like select count(*) from table? String

Objective of the Default or Defender methods in Java 8

Java 8 has included a new feature called Defender methods which allows creation of default method implementation in interface. Now first of all this is a huge paradigm shift for all condensed programmers in Java. I viewed a JavaOne 13 presentation gi

Replace the hashCode () and equal () methods

I override both the hashCode() and equals(), but I don't modify anything inside the overridden methods. @Override public int hashCode() { int hash = 7; hash = 67 * hash + Objects.hashCode(this.model); hash = 67 * hash + this.year; return hash; } @Ove

Do not get the expected result using the `compareTo ()` and `equals ()` method

I need to compare two dates. which I read one of them from my database that its type is String. so first i convert String to Date in the specific format that i need, then I get the second Date from system again in the format that I want. my problem i

Java Arrays.sort () affects the performance of other methods in my program; Why?

I am developing a java program in which I'm using a big array of instances of a Class. I have to make some calculations for every object of the array (using its Class methods). When I order the array using Arrays.Sort or other methods I notice an inc

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK