Given a 2D Array, count the number data at column 3 where it is the same.
For example,
String[][] array = {
{ "red", "value1", "alpha" },
{ "blue", "value2", "alpha" },
{ "green", "value3", "alpha" },
{ "black", "value4", "alpha" },
{ "grey", "value1", "beta" },
{ "white", "value2", "beta" },
};
int counter=0;
for(String[] subArray : array)
for(String string : subArray)
if(string.toLowerCase().equals("beta"))
counter++;
System.out.println(counter);
The output of the counter for beta = 2 and alpha = 4.
Assuming I don't know what is the exact name of the data in column 3, how I count the conditions? if(string.toLowerCase().equals(???))
Any help will be appreciated!