• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Sort Tech.

 
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Using with sorting Techinque we dont get proper sorting value
whereas the following code is getting proper sorting value
 
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i hope(in doubt too..........) the key field generally requires a object but i dont get why it is not auto boxed.
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by rex tony:
... Using with sorting Techinque we dont get proper sorting value...


What exactly does this mean? How are you sorting?
[ January 18, 2008: Message edited by: marc weber ]
 
marc weber
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by sree visu:
i hope(in doubt too..........) the key field generally requires a object but i dont get why it is not auto boxed.


What would be autoboxed? (Note that "1" is a String -- not an int.)
 
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
The reason why Map maintains the sorting order in case of Integer as a key is, the Integer class implements the Comparable Interface.

I hope it helps.

-Lave

Originally posted by rex tony:

Using with sorting Techinque we dont get proper sorting value
whereas the following code is getting proper sorting value

 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

The reason why Map maintains the sorting order in case of Integer as a key is, the Integer class implements the Comparable Interface.



What is everyone talking about? The HashMap class (used in the example) provides no ordering guarantees whatsoever.

Hery
 
Lave Kulshreshtha
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Henry,
I agree what you are saying, but when a Map is excuted with Integer as a key, then it results in sorted data.

-Lave

Originally posted by Henry Wong:


What is everyone talking about? The HashMap class (used in the example) provides no ordering guarantees whatsoever.

Hery

 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Lave Kulshreshtha:
... but when a Map is excuted with Integer as a key, then it results in sorted data.


... but since that's not guaranteed by the javadocs, it could change between JDK versions, and not be true of any other JVM to begin with. So don't rely on it.
[ January 20, 2008: Message edited by: Ulf Dittmer ]
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For the one version of the JDK that I tried (Sun Java 1.5.0_10), it wasn't true.

It wasn't insertion order. It wasn't alphabetical order. It wasn't ordered by value. And I only tried it with three keys -- which is the minimum size required to determine any order.

I was thinking it was some sort of implementation detail that requires lots of keys or lots of insertions and removals to break. Nothing. There is an order to the hashmap, but it is not any of those listed (and yes, the keys were Integers).

Henry
 
Lave Kulshreshtha
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes with various versions of jdk result varies.
We can not rely on this.
Anyway Map does not gaurentee any sorting.

- Lave
 
reply
    Bookmark Topic Watch Topic
  • New Topic