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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T22:20:12+00:00 2026-06-16T22:20:12+00:00

How to padarray in java that is add row and column to a existing

  • 0

How to padarray in java that is add row and column to a existing array in front and back with a given number.

For example :-

let x =  1  2  3
         4  5  6
         7  8  9   

and now want to 2 rows and columns of zeros in this:

   x =  0 0 0 0 0 0 0 
        0 0 0 0 0 0 0
        0 0 1 2 3 0 0
        0 0 4 5 6 0 0
        0 0 7 8 9 0 0
        0 0 0 0 0 0 0
        0 0 0 0 0 0 0

So, i want to know that is there a existing method or way to do this in java like it is available in matlab using the predefined method called padarray(x,[r,c]).

  • 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-16T22:20:14+00:00Added an answer on June 16, 2026 at 10:20 pm

    You can never add rows or columns to 2 dimensional arrays at all. Arrays are fixed size. You could use a dynamic data structure such as List<List<Integer>>.

    What you also can do is create a new array (that is bigger or smaller than your current one) using the Arrays.copyOf(int[] original, int newLength); method.

    You array x is like:

      int[][] x = new int[][]{{1,2,3}, {4,5,6}, {7,8,9}};
    

    There is no one-liner (I know of) to transform it to your desired format. You have to create a method that creates a new 2 dimensional array and place your values at the correct indexes.

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

Sidebar

Related Questions

Given an array: array1 = [1 2 3]; I have to reverse it like
I am new to Java and this I have encountered several functions that accept
What is the easiest way to (zero) pad a matlab array? i.e. given [1,2,3,4]
I would like to allocate memory for 3D array inside a function. void*** myFunc(int
I'm developing a simple SBT project that includes InputTasks for benchmarking Scala Parallel collections.
The program that I am working on takes a file and parses it line
e.g I have the original matrix (m) looks like this one 1 2 3
I have an image of size 61x56 and I want to pad the image
I am trying to create an expression tree containing a function call to a
I wrote a piece of code for computing Self Quotient Image (SQI) in MATLAB.

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.