This content has been marked as final. Show 4 replies
ArrayList + Collections.sort() is probably enough. but any collection with sorting capabilities can work.
Just how big is 'large'? Kilobytes? Megabytes? Gigabytes? The larger the file is, the more memory will be consumed trying to load and sort it all.
Indeed. If it is really 'large' by any commonly understood measure, you should certainly be using a database for this task, or an external sort, if you can find one.
EJP wrote:Even when that makes a whole lot of sense it didn't even pass my mind to suggest that...
Indeed. If it is really 'large' by any commonly understood measure, you should certainly be using a database for this task
using a H2 or HSQL database you can even solve it without needing any DBMS being installed and running.
If the inputs are small enough that you could hold them in memory, one solution is be simply to read each line into a list, then sort the list with a comparator that compares only the content of the specified column.
But, as the other posters note, if the lists are large (your definition of "large" may vary from mine), then a database may be the way to go.