Friday, 16 August 2013

Is it More Efficient to Convert String to Int or Int to String When Checking for Equality?

Is it More Efficient to Convert String to Int or Int to String When
Checking for Equality?

Following setup:
int a=3;
String b="3";
Both variables represent IDs which are semantically equal. Since the
application is for the mobile device, it is very important that the
comparison of these variables is done in the most efficient way possible.
Is it efficient to compare these variables with this snippet,
boolean areEqual = Integer.parseInt(b) == a;
or with this one?
boolean areEqual = String.valueOf(a).equals(b);

No comments:

Post a Comment