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
Jasbir21Asked:
Who is Participating?
 
kennethxuConnect With a Mentor Commented:
you can simple append " order by organname" to the end of your sql statement.
0
 
JNicCommented:
Hi,

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

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

You could use Arrays.sort() or Collections.sort().
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
JNicCommented:
Sorry, forget about that. Wait 1 minute
0
 
jimmackCommented:
;-)
0
 
JNicCommented:
Jimmack and I always post on top of each other ;-)

And yes, he is right.

0
 
Jasbir21Author Commented:
hi,
the links are like this:

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

0
 
Jasbir21Author Commented:
how do i use Arrays.sort() or Collections.sort().
0
 
JNicCommented:
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
0
 
JNicCommented:
I dont know if this solution fits to your db, but hopefully you get the idea.
Otherwise let me know.
0
 
Jasbir21Author Commented:
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
0
 
Jasbir21Author Commented:
thank you very much

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.