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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:18:53+00:00 2026-06-09T04:18:53+00:00

Gurus, I have difficulty to pass an arraylist of doubly-linked list as a parameter.

  • 0

Gurus, I have difficulty to pass an arraylist of doubly-linked list as a parameter.

I need to represent square matrices in data structure that involves linked-list. I decided to use an arraylist of doubly-linked list. Matrices information read from a text file, is stored in:

ArrayList<DoubleLinkedList<Integer>> dLLArrayList

After reads in the first input, dllArryList has content "[[5]]"

I try to create a new matrix object by calling the constructor from self-defined Matrix class:

Matrix mx1 = new Matrix (dimension, dLLArrayList);

** dimension is just an int variable that store the size of the matrix, say 1 for a 1 by 1 matrix, as indicated on the input text file.

However, as I try to print out the matrix content inside the Matrix class, it returns "[[]]":

System.out.println (this.getMatrixArrayList());

Here is the set method inside the matrix class that suppose to set ArrayList elements of a Matrix object:

public void setMatrixArrayList(ArrayList<DoubleLinkedList<Integer>> matrixArrayList) {
    for(int i = 0; i < matrixArrayList.size(); i ++){
        for (int j = 0; j < matrixArrayList.get(i).size(); j ++) {
            this.rowItemList.add(matrixArrayList.get(i).get(j));
        }
        this.matrixArrayList.add(this.rowItemList);
        this.rowItemList.clear();
    }
}

Any reason this won’t work? Suggestions, Comments?

  • 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-09T04:18:54+00:00Added an answer on June 9, 2026 at 4:18 am

    The problem is that you clear the rowItemList. When you add the rowItemList to the arraylist you just put the reference there. So when you clear it later the linkedlist just added inside the arraylist is also cleared. You need to clone the rowItemList when you add it in the outer list.

    public void setMatrixArrayList(ArrayList<DoubleLinkedList<Integer>> matrixArrayList) {
    for(int i = 0; i < matrixArrayList.size(); i ++){
        for (int j = 0; j < matrixArrayList.get(0).size(); j ++) {
            this.rowItemList.add(matrixArrayList.get(0).get(j));
        }
        this.matrixArrayList.add(this.rowItemList.clone());
        this.rowItemList.clear();
    }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Need some help from javascript gurus. I have one page where http://www.google.com/finance/converter is embedded
need help from some gurus here, I have a database which I have moved
I need some help from the shell-script gurus out there. I have a .txt
I have quick question for you SQL gurus. I have existing tables without primary
gurus. I have a perl script which needs to run in an infinite loop
Hi Javascript gurus, I have this Javascript code which is working fine on Firefox
Hope the AWK gurus can provide a solution to my problem . I have
LINQ gurus, I am looking for help to write a query... I have a
Any regex gurus around here? its driving me crazy. Say I have this string:
For you database design/performance gurus out there. If you have a database that is

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.