Frequency count

Aim: 
To write a java program that makes frequency count of letters in a given text.

Description:
 Set is an interface which does not allow any duplication in java.util package. HashSet is an implementation class for Set interface. First of all store the different types of characters in the entered line using charAt() method of String class into HashSet object. By using iterator interface get the individual characters one by one and compare that character with each and every character in that line of text using charAt() method of String class. If it matches then increment character count and display the same.

Program:
import java.util.*;
import java.io.*;
class CountLetters
{ public static void main(String args[]) throws IOException
{ BufferedReader br = new BufferedReader(new InputStreamReader(
System.in) );
HashSet<String> hs = new HashSet<String>();
System.out.println("Enter a line of text : " );
String s1 = br.readLine();
for(int i=0;i<s1.length();i++)
{ hs.add(s1.charAt(i)+"" );
}
Iterator it = hs.iterator();
while (it.hasNext() )
{ int count = 0;
String a = it.next().toString();
for(int i=0;i<s1.length();i++)
{ String b = s1.charAt(i) + "" ;
if ( a.equals(b) )
count++;
}
System.out.println(a + " count is : " + count);
}
}