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

Reply via email to