Hi, I asked a question about counting the number of times a word is in ArrayList:
ACU ACU ACU ACU ACY ACY AER AER AER AGC
So for
ACU we will get 4,
ACY we will get 2,
AER we will get 3,
AGC we will get 1.
I got some help but I cannot make it work.
Darren gave me a very important answer:
Map<String, Integer>wordCount = new HashMap<String, int>();
for(String seq : yourWordList){
wordCount.put(seq, wordCount.get(seq++));
}
But in the part wordCount.put(seq, wordCount.get(seq++));
I get an error that cannot convert from String to int, I tried to modify the code to work
but I'm getting incorrect numbers
ACU 0 ACU 1 ACU 1 ACU 1 ACY 1 ACY 2 AER 2 AER 3 AER 3
int value=0;
Map<String, Integer>wordCount = new HashMap<String, Integer>();
for(String seq : WordList){
Set<String> set = wordCount.keySet();
value = set.size();
wordCount.put(seq, value));
}
Please help me on this one. Thanks to all.