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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:04:05+00:00 2026-06-05T11:04:05+00:00

I have an interesting dilemma: I’ve got a class, let’s say it’s called FileCabinet.

  • 0

I have an interesting dilemma:

I’ve got a class, let’s say it’s called FileCabinet.

The FileCabinet stores a LinkedList of Files, called “filesInCabinet”.

Inside each File, there is yet another LinkedList of Files, called “relatedFiles”.

So it kind of looks something like this for example:

FileCabinet1

  • File1
    • File3
  • File2
    • File3
    • File4
  • File3
    • File1
    • File2
  • File4
    • File2

The problem i’m having, is the nested lists (“relatedFiles”) contain seperate instances of the Files, so in reality it’s more like:

FileCabinet1

  • File1
    • File3_duplicate
  • File2
    • File3_duplicate2
    • File4_duplicate
  • File3
    • File1_duplicate
    • File2_duplicate
  • File4
    • File2_duplicate2

With this, when I go to change a property of a File in one of the nested Lists, I want it to change the property of the real File too, but it only changes the duplicate’s property.

Is there an efficient way I can ‘match-up’ the Files within the nested Lists to the non-nested List of Files? Each File also contains unique Strings, Integers and such, so it’s easy to determine which File a duplicate is a clone of.

  • 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-05T11:04:07+00:00Added an answer on June 5, 2026 at 11:04 am

    There is an quite fast way to do this, putting all files in a set and build the related files again. Like this:

    Map<File, File> existingFiles = new Map<File, File>();
    for (File f : filesInCabinet) {
       existingFiles.put(f, f);
    }
    
    for (File f : filesInCabinet) {
       List<File> relatedFiles = f.getRelatedFiles();
       for (int i = 0; i < relatedFiles.size(); i++) {
          File relatedFile = existingFiles.get(relatedFiles.get(i));
          relatedFiles.set(i, relatedFile);
       }
    }
    

    It works just putting files into a map and replacing the files on the related list with the one that is got from Map due the equals / hashcode implementation, so when you provide a related object you get the instance from the main list (filesInCabinet).

    This means hashCode and equals needs to be implemented on File.

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

Sidebar

Related Questions

I have an interesting dilemma. If I define my class as: class Browser {
I've got an interesting dilemma now. I have a database schema like the following:
I ran into an interesting dilemma today. I have a function that handles information
I have an interesting question: I have a table with trigger names, called Foo
I have a pretty interesting dilemma that is giving me a hurricane of a
I have run into an interesting dilema. In a DataMapper class, I am generating
I have an interesting issue where a class inherits from a class that implements
I have an interesting problem. Consider this class hierachy: class Base { public: virtual
I've got an interesting dilemma that has stumped me and a coworker. I'm trying
I have somewhat interesting development situation. The client and deployment server are inside a

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.