JAVA 8 Stream API Interview Question

preview_player
Показать описание
Get the Common Prefix from the Strings
Рекомендации по теме
Комментарии
Автор

Easy Approach

Arrays.stream(str)
.reduce((s1, s2) -> {
int minLength = Math.min(s1.length(), s2.length());
int i = 0;
while (i < minLength && s1.charAt(i) == s2.charAt(i)) {
i++;
}
return s1.substring(0, i);
})
.orElse("");

ankitgupta-phnk
welcome to shbcf.ru