private void setCommonFrequency(){
Comparator<String> CommonLengthComparator = new CommonLengthComparator();
String comList = "the of and to in is that be it by are for was as he with on his at which but from has this will one have not were or all their an there been many more so when had may today who would time we about after dollars if my other some them being its no only over very you into most than they day even made out first great must these can days every found general her here last new now people public said since still such through under up war well where while years before between country debts good him interest large like make our take upon what"; //common word list
int p = 0; //start counter
while (p!=comList.length()){//while not at end of comList;
String s2 = ""; //used to id each word
String s = "" + comList.charAt(p); //used to check if current character is space
while (!s.equals(" ")){ //while next character is not a space and not at end of comList
s2 = s2 + comList.charAt(p); //word equals current word + letter at current position
if (p+1 != comList.length()){
p++;
s = "" + comList.charAt(p); //checks if next letter is space
} else {
s = " ";
}
}
s2 = s2.toString();
commonList.add(s2);
p++;
}
String[] commonListA = commonList.toArray(new String[0]); //dump commonList into an array so it can be sorted
CommonLengthComparator sorter = new CommonLengthComparator();//create a comparator
// commonList = sorter.compare(commonListA);//sort commonList according to word length, then alphabetically
Collections.sort(commonList);//use this for now to sort
Iterator it = commonList.listIterator(0); //go through the list and get each word in turn
while(it.hasNext()){ //for each word
System.out.println(it.next());
}
}