I have a method which takes in parameters in the form of a vector from another vector. This vector can be of the size 2, 3 or 4 elements.
I want to count the frequency of every word in that vector. For example, if the vector contained the strings : "hello", "my" , "hello" , I want to output an array that is [2, 1] where 2 is the frequency of hello and 1 is the frequency of my.
Here is my attempt after reading a few questions on this website:
    int vector_length = query.size();
    int [] tf_q = new int [vector_length];
    int string_seen = 0;
    for (int p = 0; p< query.size(); p++)
    {
        String temp_var = query.get(p);
        for (int q = 0; q< query.size(); q++)
        {
            if (temp_var == query.get(q) )
            {
                if (string_seen == 0)
                {
                    tf_q[p]++;
                    string_seen++;
                }
                else if (string_seen == 1)
                {
                    tf_q[p]++;
                    string_seen = 0;
                    query.remove(p);
                }
            }
        }
    }
    System.out.print(Arrays.toString(tf_q));
What is the right direction to go?
 
     
     
     
    