File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Sorting Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Sorting" Watch "Sorting" New topic
Author

Sorting

Dave Wagner
Greenhorn

Joined: Jul 05, 2007
Posts: 8
I want some feedback on the best way to sort. I have MULTIPLE Objects of the same type with many attributes. Each attribute is represented on a web page as a text box. What I will eventually do is use AJAX to narrow searches when users type in data in a text box.


How should I store these objects - in ArrayList, Properties etc that will make it easier to access each attribute ACCROSS ALL the objects?

Thanks
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9321
    
  17

Hi Dave! Welcome to javaranch.

The heading of your thread is Sorting and I think that you are talking about Storing. So there is a bit confusion. And also I didn't understand what you want. And if you want to be able to access the objects across all objects, then you will have to store it in session scope or something else. Basically can you please elaborate some more on what you want so that I can help you better


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Dave Wagner
Greenhorn

Joined: Jul 05, 2007
Posts: 8
I am talking about SORTING. I want to sort based on attributes of each object. Say I have Object A with attributes x,y and z. I have many of these objects. When a user types in a text box y, I want to be able to search all the objects of y attribute.

What is the best way of doing this? Should each object implement Comparable, Comparator, Vectors etc so that each field can be analyzed before showing a drop down list.

Hope this makes sense.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
You would only make a class implement Comparable<T> if it has a "natural order;" things like String (alphabetical order [actually called "lexical order"]) and numbers (number order) implement Comparable.
You can pass Comparator<T>s which allow you to sort on different fields at different times. There is discussion about Comparators going on here, on beginners', at present. That might help you.

Can you put your objects into a database and let the SQL do the sorting for you?

There are bound to be other ways to sort this problem.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Sorting