I created a program that checks how many times an item is repeated in an array.
However, for every item that repeats at least twice, I want to assign it to a variable. My problem is that, my list might be bigger at times or smaller. So I need my loop to go through and if a copy is found, to create a variable of type int and assign the number of repeats to it. I seem to remember reading something on Java about this, but I forgot what it's called, or I'm just confused. Please help. Thank you.
Update: I want the output to be like this:
(A : 20) - (B : 114) - (C : 50) - (W : 0)
Currently I am trying to check if
string[] art = new string[] {"ABAR 200", "CDXE 500", "BKWR 250", "BTSQ 890", "DRTY 600"};
string[] cd = new string[] {"A", "B"};
int control = 0;
//I will fill this in the first loop below with
//the first letter of each item in the art array
ArrayList firstLetter = new ArrayList ();
//this one gets filled after the second loop ends
ArrayList numOfLetters = new ArrayList ();
for(int k = 0; k < art.Length; k++){ //iterate 4 times, add 1st letter
firstLetter.Add (art[k].Substring(0, 1));
}
for (int j = 0; j < art.Length; j++) { //iterate 4 times
//check how many times a letter repeats in 'art'
while (firstLetter.Contains (art [j].Substring (0, 1))) {
control++; //
}
numOfLetters.Add ("(" + art [j].Substring (0, 1) + " " + ":" + " " +
control + ")");
control = 0;
}
print (numOfLetters[0]);
If none of this makes sense, I would be happy to just know how I can check an arraylist for how many times a letter repeats.
i,e;
ArrayList A B C A D A E F
I want to know how I can check how many times 'A' repeats
List<int>.