string comparison

As we know, equals method in string does character by character comparison. It takes 2n times to compare two equal strings of n length, as pointer will be moved for 2n times.

Can anybody tell better way to compare ? Such as n time where one pointer will be kept at the begining of the string and moving other pointer for n times .....

Please, if naybody knos then tell me...............

[406 byte] By [krishnasmart1a] at [2007-11-27 3:02:33]
# 1
How could keeping one pointer still be any use in a string comparison?String comparisons only take 2N in the case where the strings are equal. The case where they are unequal is found pretty quickly most of the time by comparing the hashcodes first.
ejpa at 2007-7-12 3:45:27 > top of Java-index,Core,Core APIs...
# 2
To confirm that two strings of length N are equal, you must examine all 2N characters.
DrClapa at 2007-7-12 3:45:27 > top of Java-index,Core,Core APIs...
# 3

I would be prepared to trust that the equals method uses the best way there is. It ought to.

In a low-level language like C or assembler on a 32 or 64 bit processor, you should be able to do better than comparing just one 16 bit code point from each string at a time. Hardly in Java. However, though I don't know, you might imagine that equals() be enough of native method to be implemented in a low-level langauge and use a trick like this.

OleVVa at 2007-7-12 3:45:27 > top of Java-index,Core,Core APIs...