WildcardMatching { public static boolean isMatch(String s, String p) { char[] cs = s.toCharArray(); char[] cp = p.toCharArray(); boolean[][] matches = new boolean[cp.length + 1][cs.length + 1]; matches[0][0] = true; for (int i = 1; i <= cp.length; i++) { if (cp[i - 1] == '*') { matches[i][0] = matches[i - 1][0]; } } for (int i = 1; i <= cp.length; i++) { for (int j = 1; j <= cs.length; j++) { if (cp[i - 1] == '*') { matches[i][j] = matches[i - 1][j - 1] || matches[i][j - 1] || matches[i - 1][j]; } else if (cp[i - 1] == '?' || cp[i - 1] == cs[j - 1]) { matches[i][j] = matches[i - 1][j - 1]; } } } return matches[cp.length][cs.length]; }  static boolean isMatch(String s, String p);  }
@Test(dataProvider = "matchObjects") public void test(String string, String pattern, boolean expected) { assertEquals(WildcardMatching.isMatch(string, pattern), expected, String.format("s: %s, p: %s", string, pattern)); }