This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Vector issue

 
mou haj
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a vector which stores say searches which the user performs in his session.. and in a page called previous search page I show them in the order they were searched.
say

Search3
Search2
Search1

now say if the user accesses search 2

Search 2
should be the 1st element
ie the 0th element..

ie I was the last accessed element to become the 0th elemnt and the rest moved back or what ever....

How to do this...

Please help
Thanks
[ June 04, 2004: Message edited by: Bear Bibeault ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64824
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Re-ordering the elements of a vector is a plain-old Java task. Nothing to do with JSP, so I'm moving this off to the Java in General(beginner) forum.
[ June 04, 2004: Message edited by: Bear Bibeault ]
 
Siyaa Hoffman
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you should consider using LinkedList in Java Collection Framework in Java2 instead of Vector.

It has methods like addFirst(),addLast() etc. which none other container has.
 
Richard Bradford
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the search is a string you could do the following:

String temp = myVector.elementAt(index);
myVector.remove(index);
myVector.addElement(0,temp);
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic