aspose file tools*
The moose likes Beginning Java and the fly likes Natural order in collections Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Natural order in collections" Watch "Natural order in collections" New topic
Author

Natural order in collections

vendikonda sravan
Ranch Hand

Joined: May 09, 2010
Posts: 38
Can Some one help me understanding natural order in collections ?
what dose it mean when we say a collection is sorted in natural order?

Thanks
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19792
    
  20

It depends on the objects. For Integer it means that, for instance, 1 < 2 and 4 < 5. For strings its lexicographical comparison: Rob > Prime because "R" comes after "P". For other classes it's defined by how the compareTo method (as required by implementing Comparable) is implemented.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Jim Hoglund
Ranch Hand

Joined: Jan 09, 2008
Posts: 525
Natural order is counting order, or alphabetical order, or date order,
or smallest to largest order, or is it largest to smallest order? Either
way is okay. This term is generally used somewhat informally so if there
is any question, make sure to find out what it means in a particular context.

Jim ... ...


BEE MBA PMP SCJP-6
Jim Hoglund
Ranch Hand

Joined: Jan 09, 2008
Posts: 525
Ey Rob : Digging slightly deeper into lexical land, natural order is:
(smallest) white space => digits => upper case => lower case (largest).
Punctuation and special characters are spread between these groups.

Jim ... ...
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19792
    
  20

If you want to be precise, in Java it's based on the int value of the individual chars, with the first 127 available on http://www.asciitable.com.
Jim Hoglund
Ranch Hand

Joined: Jan 09, 2008
Posts: 525
So a 32-bit (signed) integer conveniently covers the 16-bit UniCode space
of primitive type char. It's interesting that 0x00 is sometimes called "null"
in ASCII land, which of course it is not - it's zero.

Jim ... ...
vendikonda sravan
Ranch Hand

Joined: May 09, 2010
Posts: 38
Thanks Guys
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19792
    
  20

Jim Hoglund wrote:It's interesting that 0x00 is sometimes called "null"
in ASCII land, which of course it is not - it's zero.

I'd still call it NULL. Not only is that how it's defined in C (you know, the NULL character to terminate strings), but if you call it "zero" people may mistake it for '0' -- or 0x30.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Natural order in collections