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