473,387 Members | 1,553 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Advantage to using equals()

Hi

Whats the advantage in using .equals when comparing strings rather
than the = sign?

Thanks

NY

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*
Jul 21 '05 #1
5 1329
> Whats the advantage in using .equals when comparing strings rather
than the = sign?


I saw just in another newsgroup that somebody is paid per line that he
writes in his programs and need a general overal project rowcount for that.

It can be an advantage maybe when you are paid per character you type. For
the rest I see nothing, it needs to do a method to do the evaluation which
has surely something as the = sign in it.

Cor
Jul 21 '05 #2
There is no significant difference.
However, using the instance method Equals should save you a couple of
function calls,
and i would claim it is therefore faster, although i have never actually
tried it out.
--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"nyousfi" <ny*****@yahoo-dot-com.no-spam.invalid> wrote in message
news:41********@Usenet.com...
Hi

Whats the advantage in using .equals when comparing strings rather
than the = sign?

Thanks

NY

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*

Jul 21 '05 #3
the difference between equals() method and operator == ist that the first
one is virtual while the latter is not:

object o == "Hello";
o.equals(string.concat("He", "llo")); // will return true
o==string.concat("He", "llo") // will return false

So when using equals() it doesn't make any difference which type (object)
the variable is, only the actual type counts (string). If you use operator
== on a string variable and a object variable operator==(object, object) is
called which returns only true if and only if the objects are the same (the
same address).

--
cody

Freeware Tools, Games and Humour
http://www.deutronium.de.vu || http://www.deutronium.tk
"nyousfi" <ny*****@yahoo-dot-com.no-spam.invalid> schrieb im Newsbeitrag
news:41********@Usenet.com...
Hi

Whats the advantage in using .equals when comparing strings rather
than the = sign?

Thanks

NY

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*

Jul 21 '05 #4
cody <no****************@gmx.net> wrote:
the difference between equals() method and operator == ist that the first
one is virtual while the latter is not:

object o == "Hello";
o.equals(string.concat("He", "llo")); // will return true
o==string.concat("He", "llo") // will return false

So when using equals() it doesn't make any difference which type (object)
the variable is, only the actual type counts (string). If you use operator
== on a string variable and a object variable operator==(object, object) is
called which returns only true if and only if the objects are the same (the
same address).


Fortunately, the C# compiler will pick up the above and give you a
warning. This at least helps to reduce the occurrence of bugs caused by
this behaviour.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #5
"cody" <no****************@gmx.net>
the difference between equals() method and operator == ist that the first
one is virtual while the latter is not:

object o == "Hello";
o.equals(string.concat("He", "llo")); // will return true
o==string.concat("He", "llo") // will return false

So when using equals() it doesn't make any difference which type (object)
the variable is, only the actual type counts (string). If you use operator
== on a string variable and a object variable operator==(object, object)
is
called which returns only true if and only if the objects are the same
(the
same address).

--

Fortunately, the VB IDE will pick up the above and give you direct a
warning and wont build. In VBNet is needed to use the IS operator to compare
the adresses of Objects to give a good distinct between values. This at
least helps to reduce the occurrence of bugs caused by
this behaviour.

(You can set those warnings by option by the way in VBNet).

:-)

Cor
Jul 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Fei Li | last post by:
Hi, take string class as an example, who can explain the difference? Thanks
3
by: Frank Wisniewski | last post by:
Is this suppose to work like this: I have a class called foo in which I tried to override equals and return different answers based on what was passed in. public class foo { private string...
18
by: JohnR | last post by:
From reading the documentation, this should be a relatively easy thing. I have an arraylist of custom class instances which I want to search with an"indexof" where I'm passing an instance if the...
5
by: nyousfi | last post by:
Hi Whats the advantage in using .equals when comparing strings rather than the = sign? Thanks NY *-----------------------*
12
by: Elhanan | last post by:
hi.. i wanted to build a Dictionary Classs that will load my own class called letter, i understood that i implement the IEquatable interface's equles method that then the dictionary would use...
1
by: Omiris | last post by:
I'm trying to use the Equals() method that is defined on the List(Of T) class. The docs seem to state that if T implements the IEquatable interface, then it will use the Equals method that is...
0
by: VeeraLakshmi | last post by:
I am doing a project for internet control using Java,PHP and MySql.All sites should go through the proxy server only.We are giving access rights as allow or deny to the sites.If we type the...
10
by: AZRebelCowgirl73 | last post by:
This is what I have so far: My program! import java.util.*; import java.lang.*; import java.io.*; import ch06.lists.*; public class UIandDB {
7
by: =?Utf-8?B?QWxleCBDb2hu?= | last post by:
In C++, there is an easy technique to provide an overloaded Equals() method. A straightforward translation to C# causes a stack overflow. Why does b.Equals(ba) in the snippet below not understand...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.