Results 1 to 4 of 4
  1. #1
    javaplus is offline Member
    Join Date
    Nov 2007
    Posts
    97
    Rep Power
    0

    Default Serializing Arrays

    We can serialize objects of classes which implement Serializable interface.

    Java Code:
    import java.io.Serializable;
    public class MyClass implements Serializable{
    ...
    }
    I also understand that we can serialize Vectors as they also implement Serializable interface. Can we serialize arrays? If yes, then of which type?

    Thanks in advance.

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    Can we serialize arrays?
    You could create an ArrayList with an array. ArrayList is also serializable.
    Otherwise, probably.
    If yes, then of which type?
    Possibly most any.
    You might be able to make a class (implementing Serializable) to do the serializing for you; it could specify the array type and include the necessary methods to read and write the array. Or you could have the array (whose type implements Serializable) and the methods included in another class. This is speculation: I have never tried these.
    Object Streams

  3. #3
    javaplus is offline Member
    Join Date
    Nov 2007
    Posts
    97
    Rep Power
    0

    Default

    Ok thanks. What I understood is that if we have an Array of a type A (where A can be Integer, String etc), and A implements Serializable, then it can also be serialized.

    I will try this.

  4. #4
    javaplus is offline Member
    Join Date
    Nov 2007
    Posts
    97
    Rep Power
    0

    Default

    It worked. I tried serializing an int array it worked. Thanks.

Similar Threads

  1. new to arrays
    By jimJohnson in forum New To Java
    Replies: 1
    Last Post: 04-08-2008, 03:45 PM
  2. 2D-Arrays
    By kbyrne in forum New To Java
    Replies: 1
    Last Post: 02-07-2008, 11:08 PM
  3. arrays help
    By Warren in forum New To Java
    Replies: 6
    Last Post: 11-23-2007, 08:23 PM
  4. How do I omit an object when serializing?
    By Hasan in forum Advanced Java
    Replies: 1
    Last Post: 05-31-2007, 05:18 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •