First we pass the string to an array.
Then we go through the array and check the first and last letter of each word.
If both are "a" we eliminate it and add it to the ArrayList of eliminated words.
Then we paint the original phrase without the words removed and below the words we just deleted
String texto = "La cadena es amiga mia";
String [] array = texto.split(" ");
ArrayList eliminadas = new ArrayList<String>();
for(int i = 0; i<array.length; i++){
if(array[i].charAt(0) == 'a' && array[i].charAt(array[i].length()-1) == 'a'){
eliminadas.add(array[i]);
array[i] = "";
}
}
System.out.println( Arrays.toString(array).replace(",","") + "\n Palabras eliminadas : ");
for(int j = 0; j<eliminadas.size(); j++){
System.out.print(eliminadas.get(j) + ", ");
}
If you notice, when you paint the phrase of the words deleted, where was the word "friend" now there are two spaces, the solution to that you look for it: P