I need to delete a character from a character array and re-size the array. Until now, I have worked on replacing a particular character with a special character.
In this code I am searching for any matches that are found i.e , if any characters are matching in the male and female character array and if found I am replacing it with “*”. Instead of that I have to delete that character and resize the array.
private static void Compare(String Male,String Female) {
char[] male;
char[] female;
// converting a string into charecter array
male=Male.toCharArray();
female=Female.toCharArray();
//finding any matches i.e, any charecter is matching or not
for(int i=0;i<male.length;i++){
for(int j=0;j<female.length;j++)
{
String m = Character.toString(male[i]);
String fm = Character.toString(female[j]);
if(m.equals(fm)){
//if the charecters are equal then replacing them with "*"
male[i]='*';
female[j]='*';
}
}
}
Try this: