i have this 2d array:

String[][] testData= {
        {"s", "y", "r"},
        {"s", "n", "r"},
        {"w", "y", "r"},
        {"s", "n", "r"}
    };

how can i count the occurrence of a particular element in the column of an array?
for example i want to know how many "s" are in first column of testData

please help..........:(
thank you:

Recommended Answers

All 5 Replies

use a for loop to iterate over the first row. then, for each array you encounter, compare the first element to a value.
while doing so, keep a value in memory which is set to 0 before the loop, and which increases by 1 every iteration where you encounter the element you're looking for.
after the last iteration, you'll have the amount of arrays where the first element is the value you're looking for

use a for loop to iterate over the first row. then, for each array you encounter, compare the first element to a value.
while doing so, keep a value in memory which is set to 0 before the loop, and which increases by 1 every iteration where you encounter the element you're looking for.
after the last iteration, you'll have the amount of arrays where the first element is the value you're looking for

Thank you for your help, but still i'm in the dark :confused:

google can bring some light with keyWords For loop or Iterator

well ...
show us what you've tried so far, and what you think you can improve.
the point of this forum is to help you learn and to help you grow as a developer, but we don't intend to write the code for you.

first, break down your program in pseudocode, once you have all the steps to do, I think you'll find that the solution is not that complicated.

well ...
show us what you've tried so far, and what you think you can improve.
the point of this forum is to help you learn and to help you grow as a developer, but we don't intend to write the code for you.

first, break down your program in pseudocode, once you have all the steps to do, I think you'll find that the solution is not that complicated.

Thank you for your consideration :)

I figured it out myself yay!!! :cool:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.