Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to create and fill and array ?

Status
Not open for further replies.

tyris

Programmer
Nov 2, 2000
311
FR
sorry to post a stupid question. i think my error is very simple but i can't see it by my own

Code:
<%Iterator it = myListCurCached.iterator();
 int i=0;
 String[] myArray;
     while (it.hasNext())
     {
	myArray[i] = it.next().toString();
	i++;
     }%>

<%= myArray[3] %>

here is my code, i create an array containing strings called myArray.
and then i fill it with my iterator it.

i have this error :

Code:
97: Variable myArray may not have been initialized. myArray[i] = it3.next().toString();


do you know why ? is there a problem with the way i declare my array ?
Best regards X-),
Elise
 
You must create the array,
for example:

String[] myArray=new String[myListCurCached.size()];

Otto
 
when i put String[] myArray=new String[myListCurCached.size()];
in my code it gives me a blank page, no error is in the log file (there was error
logged before i putted this line) but nothing appears in the brower. what's wrong
? Best regards X-),
Elise
 
i've found the solution in stead of creating an iterator from the list and then to create an array with each item of the iterator i've found a method that transform the list in array :

Object[] list.toArray(Object a[]);

so here in my case it is :


String[] my Array = (String[]) myListCurHid.toArray(new String[] {});
Best regards X-),
Elise
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top