remove Chars from String - Java java.lang

Java examples for java.lang:String Replace

Description

remove Chars from String

Demo Code


//package com.java2s;

public class Main {
    public static String removeChars(String str, char[] exclude) {
        String ret = str;//w  ww  .  j  av a  2 s. c om
        for (int i = 0; i < exclude.length; i++) {
            ret = removeCharacter(ret, exclude[i]);
        }
        return ret;
    }

    public static String removeCharacter(String ret, char c) {
        String retu = "";
        for (int i = 0; i < ret.length(); i++) {
            if (ret.charAt(i) != c) {
                retu += ret.charAt(i);
            }
        }
        return retu;
    }
}

Related Tutorials