What's the quickest way to compare strings in Java? -


What is the fastest to compare two strings in Java?

Is something equal?

EDIT: I can not help a lot in clarifying the problem.

I have two strings that are sorted alphabetically and exactly the same size

Example: abbcee and abcdee

The string can be up to 30 characters long

I do not expect that the sun Oracle already has the standard < Code> String # is not optimized to maximize () , therefore, I hope this is a fast way to go. If you want to know how they have implemented it, then see a bit round in its source here. Here is a quote:

  Public boolean par (Object AObject) {If (this == Aobject } {Back true; } If (anObject instance of string) {string other string = (string) anObject; Int n = count; If (n == another string seat) {char v1 [] = value; Four v2 [] = another string.value; Int i = offset; Int j = anotherString.offset; While (n--! = 0) {if (v1 [i ++]! = V2 [j ++]) return false; } Back true; }     }     return false; }  

Comments