Pinguti Sridevi wrote:

Dear Java Friends,

The following snippet code is for storing the ArrayList values into Object array and it has to display using another loop. My requirement is I want to store only in Object[] array but not in any other data type. Its compiling but giving run time error in the following line. Can anybody give their suggestion or recode the below.

lo_oName = (Object[ ]) lo_arrListName.get(i); //giving error here in runtime.

/* FullCode */

import java.util.*;

public class Generic {

public static void main ( String args[ ] ) {

Object lo_oName[] = null;
ArrayList lo_arrListName = new ArrayList();
lo_arrListName.add("HAPPY BIRTHDAY TO YOU...............");
lo_arrListName.add("YOU ARE NOT YOU YOU ARE HE...............");
lo_arrListName.add("THE GOD...............");
lo_arrListName.add("PRAY HIM DEEPLY PEACEFULLY...............");
lo_arrListName.add("HE GIVES ALL TO YOU..............."); /*lo_arrListName.add(new Integer(100));
lo_arrListName.add(new Integer(200));
lo_arrListName.add(new Integer(300)); */
int i = 0;
System.out.println ( lo_arrListName.size());
while (i < lo_arrListName.size() )
{ System.out.println ( "In the while loop........." );
lo_oName = (Object[ ]) lo_arrListName.get(i);
System.out.println ("After storing the arraylist value in Object variable..");
System.out.println ("Value in object... " + lo_oName[i].toString() );
i++;
}
}
}




---------------------------------
Do you Yahoo!?
Yahoo! SiteBuilder - Free web site building tool. Try it!


Try,

lo_oName = (Object[ ]) lo_arrListName.toArray();

reg. s




--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to