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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:34:12+00:00 2026-06-06T01:34:12+00:00

What is the best way to store a 2D matrix of integers in Java?

  • 0

What is the best way to store a 2D matrix of integers in Java?

This matrix will be filled in from a data file, which may have different dimensions, so initializing int M[][] = new int[n][m] of some size does not work since we do not know the size of matrix and we will just iterate lines of the file and extract integers from each line (separated by a whitespace inside). So I guess to use an ArrayList of ArrayList to add integers as objects on the fly, but I’m not quite sure how to do that.

Also it is important to choose the best structure to store such matrix in terms of performance sine I’m going to iterate this matrix and do some computations.

  • 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-06T01:34:14+00:00Added an answer on June 6, 2026 at 1:34 am

    Start with an ArrayList<ArrayList<Integer>>, and then as soon as you’ve finished reading the file, turn it into an int[][] for performance.

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

Sidebar

Related Questions

Which is the best way to store a symmetric matrix in memory? It would
What is the best way to store data between program runs in Java? I
What is the best way to store data for the iPhone? I will be
Which is the best way to store meta data for a document, in the
What is the best way to store sensitive data (eg: credit cards)? I need
What is the best way to store data that is dynamic in nature using
What's the best way to store language data? Keep it as variables in some
What is the best way to store Binary data (images, pdf's, mp3's, videos ect)
I have been thinking about the best way to store product / customer /
What is the best way to store XML data used in a program ?

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.