I want to count all the letters from an input url. I don't want to discriminate between uppercase or lowercase letters. The total amounts of a's will be stored as an integer in total[0], total amount of b's in total[1], etc. etc.
Any idea how I can achieve this using InputStream?
public static int[] letterFrequency(String url) throws IOException {
InputStream inn= new BufferedInputStream((new URL(url)).openStream());
char[] c= {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'æ', 'ø', 'å'};
int[] total= new int[29];
for(int i= 0; i< c.length; i++) {
int counter= 0;
while(inn.available()!= 0) {
if(inn.read()== c[i])
counter++;
}
total[i]= counter;
}
return total;
}
EDIT:
Thank you for all the anwsers! You are great!! ;)
Mapand store each counter in it with as key the lower/upper case of the letter.Mapand thetoLowerCasemethod to ignore case. Your approach is unworkable...