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

  • Home
  • SEARCH
  • 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 8786551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:39:37+00:00 2026-06-13T21:39:37+00:00

I am trying to flatten a two dimensional array into a one dimensional array.

  • 0

I am trying to flatten a two dimensional array into a one dimensional array. This is what I currently have. I would like the flatten out my array so that the one dimensional array looks like this

   int[] oneDim = {1, 2, 3, 4, 5, 6, 7, 8 ,9 ,10, 11, 12};

This is what I currently have. I dont really know how to go about doing this. All help and input is appreciated.

   void setup() {
   int[][] twoDim = { {1, 2, 3, 4},
                      {5, 6, 7, 8},
                      {9, 10, 11, 12} }; 

   int[] oneDim = new int[twoDim.length];
   for (int i = 0; i < twoDim.length; i++) {
      for (int j = 0; j < twoDim[i].length; j++) {
        oneDim[j] += twoDim[j][i];
      }                  
    }
   println(oneDim);
  }
  • 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-06-13T21:39:39+00:00Added an answer on June 13, 2026 at 9:39 pm
    int[][] twoDim = { {1, 2, 3, 4},
                       {5, 6, 7, 8},
                       {9, 10, 11, 12} }; 
    int x = twoDim.length;
    int y = twoDim[0].length;
    int[] oneDim = new int[x*y];
    for (int i = 0; i < x; i++) {
      for (int j = 0; j < y; j++) {
        oneDim[i*y + j] = twoDim[i][j];
      }
    }
    println(oneDim);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to figure out how I can do this properly. The print_r looks like
trying to figure out why this is happening - I have an input text
I am trying to parse some XML that looks similar to this: <document> <headings>
I am currently trying to flatten a deep-structured XML document in C# so that
This is a tricky one. I an trying to flatten a LINQ object collection.
I am trying to flatten nested objects like this: public class Book { public
I'm trying to make will_paginate's :order to work with this array: @posts = current_user.subscribed_tags.map(&:posts).flatten.paginate(:page
I am trying to flatten a multi-dimensional array with ConvertAll but I can't get
I'm trying to output the keys of an array in javascript like this: data=[8,
I'm trying to flatten out a simple class that has a parent + child

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.