• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Vector issue

 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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);
reply
    Bookmark Topic Watch Topic
  • New Topic