• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Sorting

 
Dave Wagner
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9528
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Dave Wagner
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49865
71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic