Java Hungry

Remove Specific Characters from String with Example

If we are asked to remove specific or certain or unwanted characters from the string .How can we achieve this in the most efficient way ? This question has cemented its place in the technical interview of the reputed companies like Amazon or Goldman sachs .

First we need to understand the question , we need to write an algorithm to remove the certain or specific or unwanted characters from the string , for example

If the original string is "Alive is awesome" and the user inputs string to remove "alwsr" then it should print "ive i eome" as output .

If the original string is "Learning never stops" and the user inputs string to remove "estp" then the it should print "Larning nvr o" as output .
let us understand the logic and pseudo algorithm to achieve this task .

The prototype of the function to achieve result will be like this

String removeSpecificChars( String originalstring , String removecharacterstring)Logic :
We need to remove the certain characters from the original string . To achieve this , we will create a tempBoolean array , in which every index element value will be false by default . As we know if we put char in integer field , it will always print the ascii value of the character . We will pass one by one the characters of the removecharacterstring to the index of the tempBoolean array , and set the corresponding index value to true . Now iterate through the originalstring and print the character only if its value in tempBoolean is false.