I am supposed to make a custom decorator so I can replace both in an input from console and from a file:
char[
Here you have, this work 100% right for any example ....
public static void main(String[] args) {
String test = "My name is Baba";
Character[] x = { 'a', 'b' };
StringBuilder sb = new StringBuilder();
sb.append("(");
for (int i = 0; i < x.length; i++) {
if (i == (x.length - 1)) {
sb.append(x[i] + ")");
} else {
sb.append(x[i] + "|");
}
}
System.out.println(sb.toString());
Character y = 'c';
Character[] y1 = { 'd', 'e' };
if (y.getClass().isArray()) {
for (int i = 0; i < y1.length; i++) {
test = test.replaceAll(x[i].toString(), y1[i].toString());
}
} else {
test = test.replaceAll(sb.toString(), String.valueOf(y.toString()));
}
System.out.println(test);
}