• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Natural Order

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, can any one explain me about "Natural Order" in Collections. I am not able to get the concept of it.

Thanks in advance.
 
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by SrinivasaRao Madugula:
Hi, can any one explain me about "Natural Order" in Collections. I am not able to get the concept of it.

Thanks in advance.



I think this link will answer your question.
 
SrinivasaRao Madugula
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You provided me the exact answer. Thank you very much.
 
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I tried by clicking on the Link which is given Chandrashekar but could not find any answer rather I got books links.

Could you please give some inputs on the same.

Regards,
Sree
 
Ranch Hand
Posts: 2066
IntelliJ IDE Clojure Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

SrinivasaRao Madugula wrote:Hi, can any one explain me about "Natural Order" in Collections. I am not able to get the concept of it.

Thanks in advance.



It depends on you collections, for example, say, you have characters object, then natural order is their unicode values, for numbers natural order is as usual, ascending order, for String check it with java API.
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
for natural sorting there is one one interface "java.lang.Comparable". for example "TreeSet, TreeMap" internally uses this interface. In this interface "public int compareTo(Object o)" method is avilable. pre defined classes are if already comparable it means that classes implements "Comparable" interface then only natural sorting order is possible in that classes(other possibility there but default sorting not available if not comparable). That classes internally calls "compareTo()". When natural sorting is required heterogeneous objects are not allowed and null insertion is not possible.
implementation of compareTo():

returns -ve if object1 has come before object2(object1 <object2)
returns +ve if object1 has come after object2(object1 >object2)
returns 0 if object1 and object2 are equal(object1 =object2)

example
for predefined non comparable java classes natural sorting order is not available (by using Comparable interface)

remaining things digg from othe resources
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic