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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T04:57:43+00:00 2026-06-08T04:57:43+00:00

I want to serialize an Arraylist containing Date objects and then be able to

  • 0

I want to serialize an Arraylist containing Date objects and then be able to de-serialize it and iterate over the de-serialized version.

Currently I have a class called DateSerialize that implements Serializable. I have a method for adding date objects into the arraylist and then once that is done i want to serialize it.

Next time when i run the program i want to deserialize that arraylist and get those objects in the same order and format and want to run an iterator over it.

Can anyone help me out with this ??

Thanks !

  • 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-08T04:57:44+00:00Added an answer on June 8, 2026 at 4:57 am

    If you want to use Serializable, you should have no problems, because ArrayList is Serializable just as String and every primitive type. public class DateSerialize implements Serializable {} should do the rest. You can read more about this method here. However there are a lot of other options for serialization. So please be more specific.

    EXAMPLE

    First: Creating the ArrayList and the object to put in

    ArrayList aList = new ArrayList();
    MyBusinessObject obj = new MyBusinessObject();
    obj.Name = "MyName";
    obj.Address = "MyAddress";
    obj.Phone = 435345;
    aList.Add(obj);
    

    Second: serializing the ArrayList

    /// <summary>
    /// Serialize the ArrayList
    /// </summary>
    /// <param name="obj"></param>
    /// <returns></returns>
    private string SerializeArrayList(ArrayList obj) { 
      System.Xml.XmlDocument doc = new XmlDocument();
      Type[] extraTypes = new Type[1];
      extraTypes[0] = typeof(MyBusinessObject);
      System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(ArrayList), extraTypes); 
      System.IO.MemoryStream stream = new System.IO.MemoryStream(); 
      try { 
        serializer.Serialize(stream, obj); 
        stream.Position = 0; 
        doc.Load(stream); 
        return doc.InnerXml; 
      } catch { throw; } finally { 
        stream.Close(); 
        stream.Dispose(); 
      } 
    }
    

    Third: deserializing the ArrayList

    /// <summary>
    /// DeSerialize serialized string
    /// </summary>
    /// <param name="serializedData"></param>
    /// <returns></returns>
    private ArrayList DeSerializeArrayList(string serializedData) {
      ArrayList list = new ArrayList();
      Type[] extraTypes = new Type[1];
      extraTypes[0] = typeof(MyBusinessObject);
      System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(ArrayList), extraTypes);
      XmlReader xReader = XmlReader.Create(new StringReader(serializedData));
      try {
        object obj = serializer.Deserialize(xReader);
        list = (ArrayList)obj;
      } catch { throw; } finally {
        xReader.Close();
      }
    return list; 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a super class and two subclasses and I want to serialize the
I want to serialize a 'Player' class and send it over my network stream
I have a class that I want to serialize [System.Xml.Serialization.XmlTypeAttribute(Namespace = http://xyz.com/schema)] public class
I have a class that I want to serialize to xml. The class looks
I want to serialize a Map with Jackson. The Date should be serialized as
I want to serialize the Arraylist of type ArrayList<Class> and the class contains two
I have the following class that I want to serialize to an XML file
If I have a class with attributes on it's properties and want to serialize
I'm new to Java. I want to send an array (ArrayList) of objects over
I have a list of objects, say List<Topic> I want to serialize them. I

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.