It's not a secret anymore!
The moose likes Servlets and the fly likes vector pagination Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "vector pagination" Watch "vector pagination" New topic

vector pagination

michael yue
Ranch Hand

Joined: Nov 20, 2003
Posts: 204
I want to do pagination for jsp and planning to use vector for it. After I put all the data into the vactor, I not sure how to proceed. Should I use IndexOf method for vector? For example I want 20 records in a page so i should do something like below.
for(x=0, x<=myvector.lastIndexOf(), x=x+20){
(for i=0, i<=x, i++){
Is it correct? Or maybe someone have a better idea.
Praful Thakare
Ranch Hand

Joined: Feb 10, 2001
Posts: 642
Im not sure If there is any method called indexOf(int);which accepts int argument.
And I guess for your requirement you can use elementAt(int index);which will return you java.lang.Object. So you need to cast it to appropriate Class.
Hope this Helps

All desirable things in life are either illegal, banned, expensive or married to someone else !!!
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33124

Also, you only need one loop. Since you are only displaying one page at a time, you can loop through just the correct 20 elements.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
michael yue
Ranch Hand

Joined: Nov 20, 2003
Posts: 204
Will using third party components such as those in increase the performance such as becoming faster compared to vectors?
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13037
I guarantee you that the operation of Vector will never be significant in the speed of any servlet. Look at the source code for java.util.Vector - it is a really simple class.
[ March 01, 2004: Message edited by: William Brogden ]
I agree. Here's the link:
subject: vector pagination
It's not a secret anymore!