Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Convert an arraylist made up of double arrays back to array.....

807591May 23 2008 — edited May 27 2008
Here is my code:
      ArrayList distances1_list = new ArrayList();

      for (int counter=0; counter<distances1.length; counter++)
      {
         if (distances1[counter][2]<=parameters.max_distance)
         {
            distances1_list.add(distances1);
         }
      }
      System.out.println ("Size of ArrayList is: " + distances1_list.size());

/* NOW TO CONVERT THIS ARRAYLIST BACK TO AN ARRAY FOR SPEED PURPOSES */

   Double distances[][] = (Double [][])distances1_list.toArray (new Double[distances1_list.size()][]);
Unfortunately when I run it I get:

Exception in thread "main" java.lang.ArrayStoreException
at java.lang.System.arraycopy(Native Method)
at java.util.ArrayList.toArray(ArrayList.java:304)
at mcp.main(mcp.java:65)

which is the last line of the code. The original array put in the arraylist is defined as a double array.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 24 2008
Added on May 23 2008
21 comments
1,069 views