Thanks for replying. But my boss insists that I use array because vector
costs more memory and time.
>From: Shawn Zhu <[EMAIL PROTECTED]>
>Reply-To: A mailing list about Java Server Pages specification and
> reference <[EMAIL PROTECTED]>
>To: [EMAIL PROTECTED]
>Subject: Re: arrays
>Date: Wed, 20 Dec 2000 13:06:06 -0800
>
>Why don't you just use Vector?
>--------
>Vector v_queryResult = New Vector();
>...
>if(tmpString.indexOf('C')!=-1)
>{
> v_queryResult.addElement((Object)tmpString);
>}
>--------
>Then there's no need for Array2.
>
>
> > -----Original Message-----
> > From: Shirley Chen [mailto:[EMAIL PROTECTED]]
> > Sent: Wednesday, December 20, 2000 11:39 AM
> > To: [EMAIL PROTECTED]
> > Subject: arrays
> >
> >
> > Hi,
> >
> > I have a question, somebody please help me:
> >
> > I have a vector which will keep all the names the user typed
> > in. Then the
> > user supposes can do a query like "give me all the name which
> > starts with
> > 'C'". In order to do that, I do something like this:
> >
> > ...
> > String[] array1 = new String[myVector.size()];
> > String tempString = "";
> > int j=0;
> >
> > for (int i=0; i<myVector.size(); i++)
> > {
> > tmpString = (String)myVector.get(i);
> > if (tmpString.indexOf('C') != -1)
> > {
> > array1[j] = tmpString;
> > j++;
> > }
> > }
> >
> > //since array1 may not be filled up with data, I transfer it
> > to another
> > String array so I know how many element in the array
> >
> > String array2 = new String[j];
> > for (int i=0; i<j; i++)
> > {
> > array2[i] = array1[i];
> > }
> >
> > // then I will do display. Supposedly, say, array2.length is
> > 20, if the user
> > wants to display first 5, I will display only the first 5
> > records, if the
> > user wants to display 30, and I will display 20 instead.
> > ...
> >
> > I can display all the situations ok except when myVector
> > contains the names
> > that all start with "C" (which means array2.length should be
> > myVector.size()). then the program will crash. I think it
> > might be array
> > out of bound problem, but I don't know how to fix it. Please help me.
> > _________________________________________________________________
> > Get your FREE download of MSN Explorer at http://explorer.msn.com
> >
> > ==============================================================
> > =============
> > To unsubscribe: mailto [EMAIL PROTECTED] with body:
> > "signoff JSP-INTEREST".
> > For digest: mailto [EMAIL PROTECTED] with body: "set
> > JSP-INTEREST DIGEST".
> > Some relevant FAQs on JSP/Servlets can be found at:
> >
> > http://java.sun.com/products/jsp/faq.html
> > http://www.esperanto.org.nz/jsp/jspfaq.html
> > http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
> > http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
> >
>
>===========================================================================
>To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
>JSP-INTEREST".
>For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST
>DIGEST".
>Some relevant FAQs on JSP/Servlets can be found at:
>
> http://java.sun.com/products/jsp/faq.html
> http://www.esperanto.org.nz/jsp/jspfaq.html
> http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
> http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets