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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T23:50:31+00:00 2026-06-03T23:50:31+00:00

I am serializing a HashMap on my PC application using the following code: private

  • 0

I am serializing a HashMap on my PC application using the following code:

private void serialize(HashMap<Integer, Integer> map2write, String name_ser)
{// serializes fphlist into .ser file called name_ser
    FileOutputStream fileOut = null;
    try {
        fileOut = new FileOutputStream(project_dir + "/" + name_ser + ".ser");
    } catch (FileNotFoundException ex) {
        Logger.getLogger(AdminConsoleUI.class.getName()).log(Level.SEVERE, null, ex);
    }
    ObjectOutputStream out;
    try {
        out = new ObjectOutputStream(fileOut);
        out.writeObject(map2write);
        out.reset();
        out.flush();
        out.close();
        fileOut.close();

    } catch (IOException ex) {
        Logger.getLogger(AdminConsoleUI.class.getName()).log(Level.SEVERE, null, ex);
    }
}

Then I am de-serializing it in my Android application with this code:

private HashMap<Integer,Integer> deserialize_Map(String fn)
{// deserializes fn into HashMap

    HashMap<Integer,Integer> hm = new HashMap<Integer,Integer>();
    try
    {
        FileInputStream fileIn = new FileInputStream(project_dir + "/" + fn + ".ser");
        ObjectInputStream in = new ObjectInputStream(fileIn);
        hm = (HashMap<Integer,Integer>) in.readObject();
        in.close();
        fileIn.close();

   }catch(IOException i)
   {
       Log.e("MYAPP", "exception", i);
       return null;
   }catch(ClassNotFoundException c)
   {
       Log.e("MYAPP", "exception", c);
       return null;
   }catch(ClassCastException ex)
   {
       Log.e("MYAPP", "exception", ex);
       return null;
   }

    return hm;
}

In the end, I am facing two problems.

1) Deserialization takes a very long time. It contains around thousands of keys so is it normal? Is there a more efficient serialization method to tackle that?

2) After deserialization, I get a hashmap that occupies almost double the size it originally occupies on VM and when I check it in debugger, it has lots of null entries between the key values it should originally contain. However, they are not null keys but just null and I cannot view what is inside them. I debug in Eclipse. Why would it happen?

  • 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-03T23:50:32+00:00Added an answer on June 3, 2026 at 11:50 pm

    1) What is the size for the “normal” HashMap in VM size?
    I don’t think that is another solution ( if is there please someone show us) for that problem.
    You may try sharing a sqlite or something. If you like to colaborate what are you trying to solve we can propose technics that make the job faster

    Update

    You can try initializing your Map at init time ,as you suggested , with a large capacity if you know the size HashMap<Integer,Integer> hm = new HashMap<Integer,Integer>(SIZE*2);

    for the 2. from here

    An instance of HashMap has two parameters that affect its performance: initial capacity and load factor. The capacity is the number of buckets in the hash table, and the initial capacity is simply the capacity at the time the hash table is created. The load factor is a measure of how full the hash table is allowed to get before its capacity is automatically increased. When the number of entries in the hash table exceeds the product of the load factor and the current capacity, the capacity is roughly doubled by calling the rehash method

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

Sidebar

Related Questions

I am serializing objects to XML with the following code: public static string SerializeToString<T>(T
I'm serializing DataSet using GetXmlSchema() and GetXml() methods (code below), but in schema and
I am having problems serializing a cdata section using c# I need to serialize
Following my question on serializing a System.Array to a Xml string, I would like
When serializing object with the code: var xmlSerializer = new XmlSerializer(typeof(MyType)); using (var xmlWriter
I'm serializing a list of ObservableCollection<MyType> using this line of code and it works
I am serializing and deserializing following domain object to JSON using Jackson 1.8.3 public
I am serializing some C structure to string and than deserializing it with strtok()
I am serializing the following entity into XML to send to our Google Search
I am facing some issues while serializing objects (I am using JBoss Drools, and

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.