hi

    i checked the problem, i have found something other urs problem....

answer for ur problem

    initialise j as -1 i.e. instead of int j = 0 put int j = -1

and increment j before storing in the array i.e.

    ++j;
    array1[j] = tmpString;

and other things....why do u want to use the second array...u have got the
result array1 and no. matches are "j" so directly display it...
next
   tmpString.indexOf('C')  ...this function will return a positive if 'C' is
not present inthe "tmpString"....ur program will the names if the name
contains not only first alphabet as 'C'

so change it to

   tmpString.indexOf('C') == 0


   all the best
bye





----- Original Message -----
From: Shirley Chen <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, December 21, 2000 1:09 AM
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++;
>       }
> }
>
> file://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

Reply via email to