2 Replies - 10159 Views - Last Post: 15 April 2012 - 10:22 AM Rate Topic: -----

#1 robgw3   User is offline

  • D.I.C Head

Reputation: -3
  • View blog
  • Posts: 138
  • Joined: 23-February 12

Making an Arraylist serializable

Posted 15 April 2012 - 10:15 AM

I am currently working on a project for my java class, it is a bank machine application. We need to save the data entered while running the program so that it can be used again even after the program has been closed and reopened. The project suggests making it serializable, but no matter how much i search i cant seem to find any info about making an arraylist serializable that i can understand. Looking for examples of code is such a pain, all i tend to find is examples of other people using it in huge sections of code that i cant tell what is and isnt part of what i am looking for.

So could someone explain how to make an arraylist serializable?

Is This A Good Question/Topic? 0
  • +

Replies To: Making an Arraylist serializable

#2 pbl   User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8378
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: Making an Arraylist serializable

Posted 15 April 2012 - 10:20 AM

An ArrayList is serializable by default, you'll have to make serializable what you put in it:

class MyClass implements Serializable {
     String myStuff;

     // constructor 
     MyClass(String myStuff) 
        this.myStuff = myStuff;
     }

     public static void main(String[] args) {
        ArrayList<MyClass> al = new ArrayList<MyClass>(); <--- this al is serializable
     }
}


Was This Post Helpful? 2
  • +
  • -

#3 macosxnerd101   User is offline

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12324
  • View blog
  • Posts: 45,424
  • Joined: 27-December 08

Re: Making an Arraylist serializable

Posted 15 April 2012 - 10:22 AM

ArrayLists are Serializable. What you want to take a look at is implementing the Serializable interface for the classes you define that you want to Serialize. Check out this tutorial for more information.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1