Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7550931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:20:45+00:00 2026-05-30T10:20:45+00:00

After finding out the hard way that clone() does not work as intended for

  • 0

After finding out the hard way that clone() does not work as intended for multidimensional arrays, now I write

for(int k = 0; k < Nz; k++){
    for(int j = 0; j < Ny; j++){
        for(int i = 0; i < Nx; i++){
            grid_copy[i][j][k] = grid[i][j][k];
        }
    }
}           

for every array. This feels so depressingly low level and anti DRY. Could anyone suggest a more general way of doing this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T10:20:47+00:00Added an answer on May 30, 2026 at 10:20 am

    If you really really want a generic copier, I just whipped this up here and did some basic testing. It’s interesting but I don’t think it’s any better because what you gain in flexibility is lost in readability.

    private void copy(Object source, Object dest) {
        if(source.getClass().isArray() && dest.getClass().isArray()) {
            for(int i=0;i<Array.getLength(source); i++) {
                if(Array.get(source, i) != null && Array.get(source, i).getClass().isArray()) {
                    copy(Array.get(source, i), Array.get(dest, i));
                } else {
                    Array.set(dest, i, Array.get(source, i));
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Silverlight Beta 4 for a LOB application. After finding out today that
after finding out that there is a bug in the UITapGestureRecognizer ( How to
I've learned the hard way that regexes cannot adequately parse html, prior to finding
After finding out how to manually commit a Play! JPA transaction ... I'm not
after googleing a bit im stuck in finding out which SWT. flags I can
updated following Dirk's suggestion After finding out about emacs' check-parens and show-parens modes in
After finding that FutureTask running in a Executors.newCachedThreadPool() on Java 1.6 (and from Eclipse)
After being told by at least 10 people on SO that version control was
After lots of attempts and search I have never found a satisfactory way to
After hours of debugging, it appears to me that in FireFox, the innerHTML of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.