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 8850323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:52:31+00:00 2026-06-14T12:52:31+00:00

Possible Duplicate: java: How to split a 2d array into two 2d arrays What

  • 0

Possible Duplicate:
java: How to split a 2d array into two 2d arrays

What is required is to split this array:

int[][] bitblock = {
    {1,0,1,0,1,0,1,0},
    {1,0,1,0,1,0,1,0},
    {1,0,1,0,1,0,1,0},
    {1,0,1,0,1,0,1,0},
    {1,0,1,0,1,0,1,0},
    {1,0,1,0,1,0,1,0},
    {1,0,1,0,1,0,1,0},
    {1,0,1,0,1,0,1,0}};

This is an 8*8 array , I want to split it into left and right arrays and store them here:

int[][] leftblock = new int [bitblock.length][bitblock[0].length/2];
int[][] rightblock = new int [bitblock.length][bitblock[0].length/2];

I used the method Syste.arraycopy and I was able to split the bitblock to up and down arrays, I am kind of struggling to split it left and right:

System.arraycopy(bitblock, 0, leftblock, 0, leftblock.length);
System.arraycopy(bitblock, rightblock.length, rightblock, 0, rightblock.length)

Can someone please help ? Thanks

  • 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-14T12:52:33+00:00Added an answer on June 14, 2026 at 12:52 pm

    This should do the trick nicely:


    int[][] bitblock = {{1, 0, 1, 0, 1, 0, 1, 0}, {1, 0, 1, 0, 1, 0, 1, 0}, {1, 0, 1, 0, 1, 0, 1, 0}, {1, 0, 1, 0, 1, 0, 1, 0},
    {1, 0, 1, 0, 1, 0, 1, 0}, {1, 0, 1, 0, 1, 0, 1, 0}, {1, 0, 1, 0, 1, 0, 1, 0}, {1, 0, 1, 0, 1, 0, 1, 0}};

        int[][] leftblock = new int[bitblock.length][bitblock[0].length / 2];
        int[][] rightblock = new int[bitblock.length][bitblock[0].length / 2];
    
        for (int i = 0; i < bitblock.length; i++) {
            for (int j = 0; j < bitblock[0].length / 2; j++) {
                leftblock[i][j] = bitblock[i][j];
            }
    
            for (int j = bitblock[0].length / 2; j < bitblock[0].length; j++) {
                rightblock[i][j - bitblock[0].length / 2] = bitblock[i][j];
            }
        }
    

    You could also use System.arraycopy, as it makes the code more clear for future inspection.
    As of performance, I don’t think it matters as long as your array is that small.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: string split in java I have this Key - Value , and
Possible Duplicate: Java: Global Exception Handler I thought of something like this: public static
Possible Duplicate: Java - Distinct List of Objects i have a sorted array of
Possible Duplicate: Java - Leaking this in constructor In the NetBeans I have a
Possible Duplicate: Java socket sends some data during connection to server I have two
Possible Duplicate: Java how to: Generic Array creation Error generic array creation I have
Possible Duplicate: Java Calendar Setting Incorrectly i have this code: GregorianCalendar cal = (GregorianCalendar)
Possible Duplicate: Java: “implements Runnable” vs. “extends Thread” I have two questions about multithreaded
Possible Duplicate: Java split() method strips empty strings at the end? In Java, I'm
Possible Duplicate: JAVA SAX parser split calls to characters() I have an XML file

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.