Java tutorial
//package com.java2s; //License from project: Apache License public class Main { public static String removeDigit(String numStr, boolean which) { StringBuilder builder = new StringBuilder(); for (char c : numStr.toCharArray()) { if (isOddDigit(c) ^ which) { builder.append(c); } } return builder.toString(); } private static boolean isOddDigit(char c) { return c == '1' || c == '3' || c == '5' || c == '7' || c == '9'; } }