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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:15:21+00:00 2026-06-13T08:15:21+00:00

I use following complex data structure. departures = new TreeMap<String, Map<String, Set<MyObject>>>(); arrivals=new HashMap<String,

  • 0

I use following complex data structure.

departures = new TreeMap<String,  Map<String,  Set<MyObject>>>();
arrivals=new HashMap<String, Set<MyObject>>();
flights=new HashSet<MyObject>(); 

Then I use loops (I also tried other loops).

for(String dep: nizDep){
    for(String arr: nizArr){
      for(MyObject flight: _flights){
        if(flight.getFrom().equalsIgnoreCase(dep)&&flight.getTo().equalsIgnoreCase(arr)){
                    flights.add(flight);
                 }
                }
                if(!flights.isEmpty()){
            arrivals.put(arr, flights);
                    flights.clear();
                    }
            }
            if(!arrivals.isEmpty()){
            departures.put(dep, arrivals);
            arrivals.clear();
            }
    }
    System.out.println(departures.size()); //result 14
    System.out.println(departures.containsKey("Madrid")); //result true
            arrivals=departures.get("Madrid");
    System.out.println(arrivals.size()); //result 0, arrivals is empty. WHY?

My question is how to use this complex data structure and how to retrieve arrivals from departures?

  • 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-13T08:15:22+00:00Added an answer on June 13, 2026 at 8:15 am
         System.out.println(arrivals.size()); //result 0, arrivals is empty. WHY?
    

    BECAUSE When you call flights.clear(); after arrivals.put(arr, flights); or arrivals.clear(); after departures.put(dep, arrivals);, this clears your original objects(flights and arrivals). Please bring your initialization statements i.e.

            Map<String, Set<MyObject>> arrivals=new HashMap<String, Set<MyObject>>();
            Set<MyObject>(); flights=new HashSet<MyObject>(); 
    

    within the for loops or replace that statement as below:

                    if(!flights.isEmpty()){
                       Set<MyObject> newflights=new HashSet<MyObject>(); 
                        newflights.addAll(flights); //copy elements to new set
                       arrivals.put(arr, newflights);
                        flights.clear();
                    }
    

    Same you may do with departures.

    Now for retrievals:

          Set<String> arrivalKeys = departures.keySet();
          Interator<String> arrIter = arrivalKeys.iterator();
          while(arrIter.hasNext()){
            String arrKey = arrIter.next();
            Map<String, Set<MyObject>> arrivals = departures.get(arrKey );
            //use your arrivals map object
          }
    

    Same you can do to retrieve flights from arrivals e.g.

    for each arrivals retrieved as above:

          Set<String> flightKeys = arrivals.keySet();
          Interator<String> flIter = flightKeys.iterator();
          while(flIter.hasNext()){
            String flKey = flIter.next();
            Set<MyObject> flights = arrivals.get(flKey );
            //use your flights set object
          }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello Sir i want send list of data to php server i use following
I have following code to serialize my data into a file: out = new
I can use the following code for tiny little queries: DECLARE @sql VARCHAR(8000) SET
I have my own data structure written in C# (the structure is quite complex).
I use following style attribute so when i will start typing in text box
I use following code: Create a retry policy, when error, retry after 1 second,
I just use following code to add an image to my project, var paper
When i use following: var child:DisplayObjectContainer = dso.getChildAt( dso.numChildren -1 ) as DisplayObjectContainer; trace(child);
for example i use following command to find a record SELECT `users`.`mail` FROM `users`
I would like to use following sql to avoid constructing sql dynamically: SELECT CommentID,

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.