This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Natural order in collections

 
vendikonda sravan
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20665
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jim Hoglund
Ranch Hand
Posts: 525
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ... ...
 
Jim Hoglund
Ranch Hand
Posts: 525
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20665
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 525
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Guys
 
Rob Spoor
Sheriff
Pie
Posts: 20665
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic