It took a noon to get a word counter, which can be sorted by dictionary and frequency, and the function is more powerful. package treeroot.util; // anthor treeroot // since 2004-12-3public class Word {private String value; public Word (String value) {this.value = value.toLowerCase ();} private int count = 1; protected void Increase () {count ;} public string getword () {return value;} public int getCount () {return all;} public boolean equals (object o) {Return (O InstanceOf Word) && ((Word) O). Value.equals (value);} public int hashcode () {return value.hashcode ();}} package treeroot.util; // author treeroot // since 2004-12-3import java.util. *;
Public class wordcount {private static class wordset imports set {private map map = new hashmap ();
Public int size () {return map.size (); public boolean iSempty () {Return map.isempty (); public boolean contacts (Object O) {Return map.containskey (o);} public iterator item {Return map.keyset (). Iterator ();} public object [] toservation () {return map.keyset (). Toarray ();} public object [] toservation (object [] a) {return map.keyset ) .toArray (a); public boolean add (object o) {if (map.containskey (o)) {(word) map.get (o)). Increase ();} else {map.put (O , o);} return true;} public boolean remove (Object o) {return false;} public boolean addAll (Collection c) {return false;} public boolean removeAll (Collection c) {return false;} public boolean retainAll (Collection c) {RETURN FALSE;} public boolean containsall (Collection C) {Return map.keyset (). ContainSall ();} public void clear () {} public boolean equals (object c) {return map.keyset (). PUBLIC INT Hashcode () {Return map.keyset (). hashcode ();}}
Public static set getword (string s, comparator order) {set set = new wordset (); string split1 = "[^ a-za-z // -_ '] "; string split2 = "[^ A-ZA- Z] [// -_ '] [^ a-za-z] * "; string split3 =" [^ a-za-z] * [// -_'] [^ a-za-z] "; String regex =" (" split2 ") | (" split1 ") "; string [] Words = S.Split (regex); for (int i = 0; i