Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2003

Tip: Looking for answers? Try searching our database.

How to sort a textarea input with java?

Thread view: 
wayne - 19 Nov 2003 18:50 GMT
Hi,

A textarea input in a form of

ID_1    5
ID_2    7
ID_3    9
ID_4    8
....    

....

ID_100  7.5

will be received by request.getParameter as:

"ID_1 5 ID_2 7 ID_3 9 ID_4 8 ................"  

Is there anyway to sort the input to an array or TreeMap?  

Thanks a lot?
nos - 19 Nov 2003 18:59 GMT
easy if you use split()

> Hi,
>
[quoted text clipped - 17 lines]
>
> Thanks a lot?
wayne - 25 Nov 2003 20:05 GMT
Yes, after JDK 1.4. It's very convenient.  Much easier than to read
Excel files.  Especially I only need 1 column most of the time.
Thanks a lot.

Wayne

> easy if you use split()
>
[quoted text clipped - 19 lines]
> >
> > Thanks a lot?
steve souza - 30 Nov 2003 03:33 GMT
I have released the Open Source FormattedDataSet API.  It has a couple
utility methods that will help you get the sorting done (Utils and
Array

Here is the code:

// convert request parms to an array
String[][] params=Utils.getParameters(request);
// sort by column 2 (arrays start at 0) in ascending order.  after
this call the array is sorted
ArrayComparator.sort(params, 1, "asc");

The array is now sorted.  If you want to sort by more than 1 column
you can do the following

ArrayComparator ac=new ArrayComparator();
ac.addSortCol(1,"desc");
ac.addSortCol(3,"asc");
ac.sort(myArray);
// the array will be sorted.  this is similar to a SQL order by
clause.
// i.e. when array indexing is accounted for it is similar to 'order
by col2 desc, col4 asc'

The FormattedDataSet does much more than this.  It is the easiest way
I have seen to generate dynamic text including html and xml.

Visit http://www.fdsapi.com to see a live demo that converts request
params into various outuputs (including html, csv, and xml), and to
see the java docs for the ArrayComparator.

steve - http://www.fdsapi.com, http://www.jamonapi.com
Roedy Green - 19 Nov 2003 19:37 GMT
>Is there anyway to sort the input to an array or TreeMap?

TreeMaps keep themselves sorted. to sort arrays and ArrayLists see
http://mindprod.com/jgloss/sort.html

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.