• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 218
  • Last Modified:

String equals performance

Hi,

String abc = "test";
if ("test".equals(abc))

is thre any performance issues in the above line of code?.

Thank you
0
mmsreddy
Asked:
mmsreddy
  • 3
  • 3
1 Solution
 
objectsCommented:
no
0
 
sciuriwareCommented:
Depends on what you want.
Usually code like this is OK.
In this special case:

if("test" == abc)

is much faster, but only because we know that JAVA allocates only ONE instance
of the literal string "test".
In general such usage is tricky, because mistakes are easily made
to the profit of nanoseconds, while every change to a program might
corrupt the "smart" code.

;JOOP!

0
 
CEHJCommented:
>>is thre any performance issues in the above line of code?.

Compared to what other code?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
sciuriwareCommented:
I believe the question was: is this smart / efficient enough?

We all think: Yes.

;JOOP!
0
 
CEHJCommented:
btw

>>
if("test" == abc)

is much faster
>>

reference equality (understandly) is the first thing that String.equals checks for so there's no need anyway to write that
0
 
sciuriwareCommented:
Really? Smart!

;JOOP!
0
 
CEHJCommented:
Yep ;-)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now