Welcome to Dream.In.Code
Become a Java Expert!

Join 150,197 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 2,031 people online right now. Registration is fast and FREE... Join Now!




Arraylist - natural order

 
Reply to this topicStart new topic

Arraylist - natural order, Probably a dumb question..

anorman
23 Sep, 2008 - 07:31 PM
Post #1

New D.I.C Head
*

Joined: 30 Jan, 2008
Posts: 14

I am working with a collection of doubles and when a number is added to the list it needs to maintain the natural order. Honestly Im not quite sure what that means. I figure I can use list.add(index, number) but Im not sure how to figure out where in the list will the number go...because i have no idea what the "natural order" would be. Any explanation on this would be awesome.
User is offlineProfile CardPM
+Quote Post

pbl
RE: Arraylist - Natural Order
23 Sep, 2008 - 07:56 PM
Post #2

D.I.C Lover
Group Icon

Joined: 6 Mar, 2008
Posts: 3,587



Thanked: 233 times
Dream Kudos: 75
My Contributions
QUOTE(anorman @ 23 Sep, 2008 - 08:31 PM) *

I am working with a collection of doubles and when a number is added to the list it needs to maintain the natural order. Honestly Im not quite sure what that means. I figure I can use list.add(index, number) but Im not sure how to figure out where in the list will the number go...because i have no idea what the "natural order" would be. Any explanation on this would be awesome.

Depends how often you need it sorted.
If you always needed sorted then you'll have to implement your own binary tree.
If not, you can always extract it to an array of double and sort it throught the Arrays.sort() method
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 04:44AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month