Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to extract the left most common characters in a string list?

Tags:

java

string

Assume I have the following list of string objects:

ABC1, ABC2, ABC_Whatever

What's the most efficient way to extract the left most common characters from this list ? So I'd get ABC in my case.

like image 290
Muhammad Gelbana Avatar asked Aug 10 '13 16:08

Muhammad Gelbana


People also ask

How do you find the common string between two strings?

To find common substrings between two strings with Python, we can use the difflib module. We have 2 strings string1 and string2 that we want to find the common substring that's in both strings. To do that, we use the SequenceMatcher class with string1 and string2 .


1 Answers

StringUtils.getCommonPrefix(String... strs) from Apache Commons Lang.

like image 136
Robert Avatar answered Oct 08 '22 09:10

Robert