I am trying to write a code that finds the frequency of characters in a String entered in the method (phraseList() is an already working method that takes a word and puts each character in an arrayList)
and returns in a new List that has the letters and their frequency, my code below;
public List <String> ltrfrq(String phrase){
List <String> list0 = new ArrayList<String>();
int count = 1;
List <String> list = phraseList(phrase.toUpperCase());
for(int i = 0; i < list.size(); i++){
for(int j = i + 1; j < list.size(); j++){
if(list.get(i).equals(list.get(j))){
count++;
}
}
if(list.get(i).equals(" ")){
list0.add("Space" + "-" + count);
}
else{
list0.add(list.get(i) + "-" + count);
}
count = 1;
}
return list0;
}
}
My problem however is that it returns all the letters and although I have tried many methods to remove them like using the remove() method, it still does not work, I had something like
list.remove(list.get(i));
i--;
Can anyone help me?