Write code to remove all occurrences of the supplied Chars from a string
//package com.book2s; public class Main { public static void main(String[] argv) { String s = "book2s.com"; char[] chr = new char[] { 'b', 'o', 'o', 'k', '2', 's', '.', 'c', 'o', 'm', 'a', '1', }; System.out.println(removeChars(s, chr)); }/*ww w . ja v a 2 s. c o m*/ /** * This method takes a String as an argument and removes all occurrences of * the supplied Chars. It returns the resulting String. */ public static String removeChars(String s, char[] chr) { StringBuilder sb = new StringBuilder(s.length()); for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); if (!charMatch(c, chr)) { sb.append(c); } } return sb.toString(); } private static boolean charMatch(int iChr, char[] chr) { for (int i = 0; i < chr.length; i++) { if (iChr == chr[i]) { return true; } } return false; } }