You cannot "implement HashMap". HashMap is a class. You can extend it. Or you can implement the Map interface.
Have you read my reply? Hash-based structures are by definition unsorted.
You need to re-think what you want to do, or re-state your problem in more concrete terms so that people can understand it.
> You cannot "implement HashMap". HashMap is a class.
> You can extend it. Or you can implement the Map
> interface.
>
> Have you read my reply? Hash-based structures are by
> definition unsorted.
>
> You need to re-think what you want to do, or re-state
> your problem in more concrete terms so that people
> can understand it.
You mean to say that .We have to put the data after sorting it.
Hi,
I appreciate that English isn't your native tongue, but I'm struggling to understand you.
I will assume you meant your last message to be one sentance with a question mark at then end.
No. Putting sorted data into a hash-based structure will not solve the problem. Think about how a hashed structure (e.g. HashMap) works. Without additional help, there is no way of knowing what the "sorted" order of elements is. And sorted might be defined by some natural sorting order, or by order of insertion.
Short of using a non-hashed structure (e.g. a TreeMap as somebody else suggested), the only choice you have is to sort the data after you retrieve it.
Actually... if you are happy to sort the data prior to insertion, you could use LinkedHashMap which does maintain insertion order - but it does it at the cost of having to maintain both a HashMap and a LinkedList running through the same data.