I am developing Java application and am new to using TreeMap. The program needs to keep track of the number of incidents of each word in the text file, however, I am having trouble putting my data in the treemark.
When I use the same exact code to insert data in a hashmap, then I work properly, but I need value.
I have been working on this for two days and completely stumped!
The word class: Is applied to {this.tesdxt = s; Thnt = 1; } Public int coeTo (object x) {sd if (thiunt & lt; temp.count) {return return 1; } Sd} Public Zero inemnt () {this.cot ++; } Public spoken equivalent (object obj) {d temp = ((ls (temp.text) and this.unt == temp.count;} public int hashCode () {return.tshCode ()} + Integer.toSsdtring ( Calculation) .hashCode ();} public string toasting () {this.text return}}counting class:
Public class calculation {public mathematics} () {} public iutTest () {for (int i = 0; i <5; i ++) {sortedCoun.put (new word ("testword #" + i) , 1);} Backdated wordcaves size ();}}
Commuter class:
public class Sort appleter impleWord, integer & gt; c Sha} {this.map = map;} public int comparison (object o1, object o2) {if!! Map.consKey (o1) ||! Map.coninsKey (o2)) {return 0;} if (mapet OA1)) & lt; map.get (o2)) {retrn ap.get (o2)) {return 0; } E {Return -1; }}}}}
There are several problems with your code.
First of all, a TreeMap has been ordered by its keys; Its not value.
Second, you can not use something as a key if its value can be changed into a map or set (where the value corresponds to its equivalent () method.) < / P>
Thirdly, you should not apply the same () without applying the hash code ().
They should get you the way there!
No comments:
Post a Comment