Link to home
Start Free TrialLog in
Avatar of Jasbir21
Jasbir21

asked on

Link to display alphabetically

hi,
  I have an application when the user enter search the links gets displayed.

How do i do it, if i want to display link alphabetically,
For example:

if user enter little, big
should be displayed like this

big

little

Thanks
Avatar of JNic
JNic

Hi,

In what form are your links? Are the Strings or...?

Could you write a few example links?
How are the links stored?

You could use Arrays.sort() or Collections.sort().
Sorry, forget about that. Wait 1 minute
;-)
Jimmack and I always post on top of each other ;-)

And yes, he is right.

Avatar of Jasbir21

ASKER

hi,
the links are like this:

<a target='mypopup' href='popup.jsp?organizationid=<%=rs.getString( "organname") %>'><%=rs.getString("organname")%></a>

how do i use Arrays.sort() or Collections.sort().
Do something like this:

import java.util.Vector;
import java.util.Collections;

Vector v = new Vector();
while (rs.next()){
  String organname=rs.getString("organname");
  v.add(organname);
}
Collections.sort(v);
for (int i=0; i<v.size(); i++){
   out.println("<a target='mypopup' href='popup.jsp?organizationid="+v.elementAt(i)+">'>"+v.elementAt(i)+"</a>";
}

Hope it helps,

Nic
I dont know if this solution fits to your db, but hopefully you get the idea.
Otherwise let me know.
hi,

I tried that :

..........part of the code:
     do
         {

String organname=rs.getString("organname");
if(!v.contains(organname)){

v.add(organname);

Collections.sort(v);
for (int i=0; i<v.size(); i++){

   out.println("<a target='mypopup' href='popup.jsp?organizationid="+v.elementAt(i)+"'>"+v.elementAt(i)+"</a>");



%>



<br>


<%


}
}
         }while(rs.next());
     }
.........

I don't know why duplicate links are being displayed eventhough i put a distict link in sql statements as well as
if(!v.contains(organname))

and the link are not displaying ailphabetically.

Did i miss anything, thanks
ASKER CERTIFIED SOLUTION
Avatar of kennethxu
kennethxu

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thank you very much