private static ArrayList getMaxSubString(String s1,String s2) { //最大相同子串,s1,s2=min String max=(s1.length()>s2.length())?s1:s2; String min=(max==s1)?s2:s1; ArrayList list =new ArrayList (); //循环短的字符串来做截取 for(int x=0;x 0){return list;} } return list; }
@Test public void maxsubsting(){ String s1="abjdfhelloshdf"; String s2="dflo"; ArrayList list =getMaxSubString(s1,s2); System.out.println(list.size()); if (list.size()>0){ for (Iterator iterator =list.iterator();iterator.hasNext();){ System.out.println(iterator.next()); } }