I am supposed to make a custom decorator so I can replace both in an input from console and from a file:
char[
There is a more faster way:
public static void main(String[] args) {
String target = "ab";
String replacement = "**";
char[] array = "abcde".toCharArray();
for (int i = 0; i < array.length; i++) {
int index = target.indexOf(array[i]);
if (index != -1) {
array[i] = replacement.charAt(index);
}
}
System.out.println(array);
}