Given a 2D array and a string, how can I remove a row which does not contain a specific string? So far, I created a nested for loop which iterates through the array, adding all adjacent elements(except the string itself) to an ArrayList. However, I do not want to include elements from rows that exclude the specified string.
String letters[][] =
{
{"a", "b"},
{"s"}
};
If the string is "a", the list should include "b". However, my list also includes "s" because it is not equal to the string. How can I write my code so that only elements that share the same row as the specified string are added to the list?