java me - Sorting a hashtable based on its entry value (not the key) -


I have to work the following code in the Java ME / J2ME environment. Please help:

 Hashtable  

This does not work, I get an error:

Exception to "main" java.lang.ClassCastException thread: java.util.Hashtable $ Entry can not be entered in java.lang. This code, which I have indicated in the code, with a comment, using I J2me!

The code you received is not anywhere valid J2ME, it is full fat (J2SE) Java; J2ME currently has no generic, or collections class or comparative interface - check Java Dock for and for components of J2ME Your error mentions those people, so definitely J2ME did not come from, which suggests that you are doing fundamental mistakes in your project setup?

If you want to do it in J2ME, you should work yourself one type, because as far as I can not tell such a thing exists. Writing bubbles will be easy, because the only way is that you can easily access sequential members of the hashtable through Enumerations (via scores.keys () and scores.values ​​()). Suppose you want to sort your activities in ascending order based on the order of the floats, with which they are connected, you want something like this:

  Bullion Fixed Point = False; While (fixed point!) {FixedPoint = true; Calculation e = scores.keys (); If (EHasMoreElements ()) return; Object previous key = e.nextElement (); While (e.hasMoreElements ()) {Object current = EXAlment (); If (float) score.get (current)> (float) score.get (previous)) {swap (current, past); FixedPoint = false; } Of the previous = turned on; }}  

In addition to this, you must write a swap function somewhere that swaps two elements of hashbil when keys are given to it, it is worth noting that this is not the fastest possible implementation. - Bubble sort will not be good if you expect big lists on the other hand, with limited tools it is very easy that J2ME gives you!


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -