|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Generate data entry and reporting .NET Web apps in minutes, straight from your database. Read our FREE whitepaper “Build Web 2.0 Applications Without Hand-Coding” Download now! |
|
#1
|
|||
|
|||
|
Hi
I have an external text file with some data. I manage to extract the data out and each piece of data consist of many fields. Before displaying the data on a JSP page, I need to sort all the data by a particular field. What I have done is actually put all the data into a 2D array and sort them. But because there are too much data, the processing and computation take very long. Does anybody have a better idea or solution to go around this? Thanks.... |
|
#2
|
|||
|
|||
|
Use a database?
Maybe you could provide a text file that is pre-sorted? This doesn't sound like something you're going to be wanting to do every time you view the page. |
|
#3
|
|||
|
|||
|
Since you're in java, another thing you can do is have a servlet that loads the text file, sorts it and keeps it in an object that your other page uses. Depending on how the data is updated the serlvet could reload the text file every hour, or check time of last change or whatever. Since servlets stay in memory they can have data that lasts between requests.
|
|
#4
|
|||
|
|||
|
hhmmm... what I do is the following:
1o.) I have a vector of objects (these objects are javaBeans). Every object has many fields (price,name, you name it). 2o.) now, you can put this vector in a session (in my case the vector is not too big, so I don't have performance issues). 3o. ) now, my javabeans implement the comparable interface, something like this: public class Employee implements Comparable { public static final Comparator SOC_SEC_ORDER = new Comparator( ) { public int compare(Object o1, Object o2) { Employee emp1 = (Employee)o1; Employee emp2 = (Employee)o2; return emp1.getSocSecNum( ).compareTo(emp2. getSocSecNum( )Here; } }; public static final Comparator NAME_ORDER = new Comparator( ) { public int compare(Object o1, Object o2) { Employee emp1 = (Employee)o1; Employee emp2 = (Employee)o2; return emp1.getName( ).compareTo(emp2. getName( ) Here; } };} 4o.) now, the only thing you do to order is. Collections.sort(myVector,SOC_SEC_ORDER) and that's it. Remember, your beans must be serializable so you don't have memory problems.. hope it helps andres |
|
#5
|
|||
|
|||
|
ooppss.. screwed up my code. sorry.
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Java Help > sorting of data from a file |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|