Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (13.1k points)
I was trying to create a function which does binary search but it require to compare two strings. Is there any function available to compare two strings in a single iteration of binary search?

1 Answer

0 votes
by (26.7k points)

You can use te=he simple localCompare() function:

string_a.localeCompare(string_b);

/* Expected Returns:

 0:  exact match

-1:  string_a < string_b

 1:  string_a > string_b

 */

I hope this will help.

Want to become a Java Expert? Join Java Training now!!

Want to know more about Java? Watch this video on Java Tutorial | Java Course:

Related questions

0 votes
1 answer
asked Aug 10, 2019 in Java by Suresh (3.4k points)
0 votes
1 answer
0 votes
1 answer
asked Nov 23, 2020 in SQL by Appu (6.1k points)
0 votes
1 answer
asked Mar 17, 2021 in Java by dante07 (13.1k points)

Browse Categories

...