Results 1 to 2 of 2
  1. #1
    xael is offline Member
    Join Date
    Sep 2010
    Posts
    31
    Rep Power
    0

    Default Copying array values without creating just a reference.

    How do you copy the values of one array to another without the 2nd array just being a reference to the first? I need to be able to copy an array and modify the original without those modifications getting passed to the copy.

    here's my code

    Java Code:
    // there's a matrix of Doubles called columns: the one I want to copy
    for (int i = 0; i < rowlength ; i++) {
                for (int e = 0; e < rowlength ; e++) {
                //copy
                    Double d= new Double(columns[i][e]);
                    prevcolumns[i][e]=new Double(d.doubleValue());
                }
    
            }
    
    
    for (int i = 0; i < size; i++) {
                for (int e = 0; e < size; e++) {
                   
                    columns[30 + i][30 + e] += 1;
    
                }
    
            }
    // for any columns[i][e] it is the same as prevcolumns[i][e]... which is bad
    thanks for any thoughts

  2. #2
    xael is offline Member
    Join Date
    Sep 2010
    Posts
    31
    Rep Power
    0

Similar Threads

  1. Trouble copying an array
    By xXRedneckXx in forum New To Java
    Replies: 10
    Last Post: 02-05-2011, 06:36 PM
  2. Replies: 14
    Last Post: 01-22-2011, 03:36 PM
  3. Copying ArrayList into an Array
    By Manfizy in forum New To Java
    Replies: 6
    Last Post: 07-16-2009, 08:03 AM
  4. creating a reference to a value in a map
    By kellykellykelly in forum Advanced Java
    Replies: 1
    Last Post: 02-28-2009, 08:59 AM
  5. Creating Folder in JAVA and Copying File
    By fnoman in forum New To Java
    Replies: 8
    Last Post: 10-18-2008, 08:33 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •