@Test public void searchSubstring() { String str1 = "www.taobao.com"; String str2 = "taobao"; System.out.println("str1: " + str1 + ", str2:" + str2 + ", result: " + StringRelated.searchSubstring(str1, str2)); }
public static int searchSubstring(String str1, String str2) { if (str1 == null || str2 == null || "".equals(str1) || str1.length() < str2.length()) { return -1; } int methodFlag = 1; int res1 = -1; int res2 = -1; try { res1 = (int) StringRelated.class.getMethod("searchMethod" + methodFlag, String.class, String.class).invoke(StringRelated.class, str1, str2); methodFlag = 2; res2 = (int) StringRelated.class.getMethod("searchMethod" + methodFlag, String.class, String.class).invoke(StringRelated.class, str1, str2); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { e.printStackTrace(); } assert res1 == res2; return res1; }
StringRelated { public static int searchSubstring(String str1, String str2) { if (str1 == null || str2 == null || "".equals(str1) || str1.length() < str2.length()) { return -1; } int methodFlag = 1; int res1 = -1; int res2 = -1; try { res1 = (int) StringRelated.class.getMethod("searchMethod" + methodFlag, String.class, String.class).invoke(StringRelated.class, str1, str2); methodFlag = 2; res2 = (int) StringRelated.class.getMethod("searchMethod" + methodFlag, String.class, String.class).invoke(StringRelated.class, str1, str2); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { e.printStackTrace(); } assert res1 == res2; return res1; } }
StringRelated { public static int searchSubstring(String str1, String str2) { if (str1 == null || str2 == null || "".equals(str1) || str1.length() < str2.length()) { return -1; } int methodFlag = 1; int res1 = -1; int res2 = -1; try { res1 = (int) StringRelated.class.getMethod("searchMethod" + methodFlag, String.class, String.class).invoke(StringRelated.class, str1, str2); methodFlag = 2; res2 = (int) StringRelated.class.getMethod("searchMethod" + methodFlag, String.class, String.class).invoke(StringRelated.class, str1, str2); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { e.printStackTrace(); } assert res1 == res2; return res1; }  }
StringRelated { public static int searchSubstring(String str1, String str2) { if (str1 == null || str2 == null || "".equals(str1) || str1.length() < str2.length()) { return -1; } int methodFlag = 1; int res1 = -1; int res2 = -1; try { res1 = (int) StringRelated.class.getMethod("searchMethod" + methodFlag, String.class, String.class).invoke(StringRelated.class, str1, str2); methodFlag = 2; res2 = (int) StringRelated.class.getMethod("searchMethod" + methodFlag, String.class, String.class).invoke(StringRelated.class, str1, str2); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { e.printStackTrace(); } assert res1 == res2; return res1; }  static void main(String[] args); static void printOddAndEvenInorderByTwoThread(); static int searchSubstring(String str1, String str2); static int searchMethod1(String str1, String str2); static int searchMethod2(String str1, String str2); static void charFrequency(String[] strArray); static int searchMaxLengthMethod1(String s, int k); static int searchMaxLengthMethod2(String s, int k); static void searchLongestRepeatedSubstringMethod1(String originStr); static String searchLongestRepeatedSubstringMethod2(String originStr); static boolean wordMatch(char[][] chars, int arrayWidth, String word); }
StringRelated { public static int searchSubstring(String str1, String str2) { if (str1 == null || str2 == null || "".equals(str1) || str1.length() < str2.length()) { return -1; } int methodFlag = 1; int res1 = -1; int res2 = -1; try { res1 = (int) StringRelated.class.getMethod("searchMethod" + methodFlag, String.class, String.class).invoke(StringRelated.class, str1, str2); methodFlag = 2; res2 = (int) StringRelated.class.getMethod("searchMethod" + methodFlag, String.class, String.class).invoke(StringRelated.class, str1, str2); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { e.printStackTrace(); } assert res1 == res2; return res1; }  static void main(String[] args); static void printOddAndEvenInorderByTwoThread(); static int searchSubstring(String str1, String str2); static int searchMethod1(String str1, String str2); static int searchMethod2(String str1, String str2); static void charFrequency(String[] strArray); static int searchMaxLengthMethod1(String s, int k); static int searchMaxLengthMethod2(String s, int k); static void searchLongestRepeatedSubstringMethod1(String originStr); static String searchLongestRepeatedSubstringMethod2(String originStr); static boolean wordMatch(char[][] chars, int arrayWidth, String word);  }