Home arrow static arrow Java Programming [Archive] - ArrayList to array problem
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - ArrayList to array problem
This topic has 5 replies on 1 page.

Posts:30
Registered: 10/30/01
ArrayList to array problem  
Apr 2, 2004 1:42 AM



 
I have an arraylist...and i want to convert it into an array but i got an error...below is my code...

double [] array = new double [26]; ArrayList [] my_frequency_array  = get_frequency_table(key_length, array_buffer); for (int u=0; u < my_frequency_array.length; u++)        {               array[u] = my_frequency_array[u].toArray(new double[u]);               System.out.println("Value for " + u);        } 


Error:

Crypto/GuiCrypto.java:292: cannot resolve symbol
symbol : method toArray (double[])
location: class java.util.ArrayList
array = my_frequency_array.toArray(new double);
 

Posts:26
Registered: 8/8/03
Re: ArrayList to array problem  
Apr 2, 2004 1:52 AM (reply 1 of 5)



 
The .toArray method needs an object array. "double" is not an object in java.
 

Posts:16
Registered: 6/29/04
Re: ArrayList to array problem  
Jul 22, 2004 1:06 AM (reply 2 of 5)



 
Hi,
I am also facing this problem.
I have a ArrayList of Integer Objects. I want to convert to double array. How to do? Could you please help me understand this.
Example:
ArrayList num has 2,3,4,5 Integer Objects
i want to convert it to following double array , like this-
double darr[ ]={2.0,3.0,4.0,5.0}
 

Posts:24,036
Registered: 2/3/03
Re: ArrayList to array problem  
Jul 22, 2004 5:38 AM (reply 3 of 5)



 
Iterate through the array, storing the int value as a double.
 

Posts:24,036
Registered: 2/3/03
Re: ArrayList to array problem  
Jul 22, 2004 5:39 AM (reply 4 of 5)



 
Correction - iterate through the List...
 

Posts:196
Registered: 6/29/04
Re: ArrayList to array problem  
Jul 22, 2004 5:44 AM (reply 5 of 5)



 
In Jav 5:
import java.util.*; public class Example {    public static void main(String[] args) {        List<Integer> ints = new ArrayList<Integer>();        for(int i=0; i<10; ++i)            ints.add(i);         double[] dubs = new double[ints.size()];        int offset=0;        for(double val : ints)            dubs[offset++] = val;        System.out.println(Arrays.toString(dubs));    }}
 
This topic has 5 replies on 1 page.