@@ -0,0 +1,971 @@
+package com.levelup.java.string;%0A%0Aimport static org.junit.Assert.assertEquals;%0A%0Aimport org.apache.commons.lang3.StringUtils;%0Aimport org.junit.Test;%0A%0Aimport com.google.common.base.Strings;%0A%0A/**%0A * This java example will demonstrate finding %0A * common prefix between two strings.%0A * %0A * @author Justin Musgrove%0A * @see %3Ca href='http://www.leveluplunch.com/java/examples/common-prefix-between-strings/'%3ECommon prefix%3C/a%3E%0A * %0A */%0Apublic class CommonPrefixBetweenStrings %7B%0A%0A%09%0A%09@Test%0A%09public void find_common_prefix_between_strings_guava ()%7B%0A%09%09%0A%09%09String phrase1 = %22semicircle%22;%0A%09%09String phrase2 = %22semiconductor%22;%0A%09%09%0A%09%09String prefix = Strings.commonPrefix(phrase1, phrase2); %0A%09%09%0A%09%09assertEquals(%22semic%22, prefix);%0A%09%7D%0A%09%0A%09@Test%0A%09public void find_common_prefix_between_strings_apache_commons () %7B%0A%0A%09%09String phrase1 = %22semicircle%22;%0A%09%09String phrase2 = %22semiconductor%22;%0A%09%09%0A%09%09String prefix = StringUtils.getCommonPrefix(phrase1, phrase2); %0A%09%09%0A%09%09assertEquals(%22semic%22, prefix);%0A%0A%09%7D%0A%09%0A%09%0A%7D%0A

add common prefix between strings