answersLogoWhite

0

Can you serialize the ArrayList class in Java?

Updated: 8/19/2019
User Avatar

Wiki User

12y ago

Best Answer

The ArrayList class itself is serializable and will serialize if it contains only serializable objects.

If, however, you add non-serializable objects into the list then it will not serialize, but will throw a NotSerializableException.

User Avatar

Wiki User

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Can you serialize the ArrayList class in Java?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What are the requirements to download a java arraylist?

The requirements to download a java arraylist are a pc with java software installed. A java arraylist is used to store a group of elements in a specific order.


What type of platform does Arraylist Java run on?

Arraylist Java runs on Oracle which is a relational data management database produced by the Oracle Corporation. Arraylist Java has been part of the Java framework ever since Java 5.


How you can store a class variables in array list?

An (non generic) arrayList in java can save any type of object (in this case your class variable) in this straightforward way: MyClass myClassVar = new MyClass(); ArrayList myArrayList = new ArrayList(); myArrayList.add(myClassVar);


How can you sort an arraylist of strings?

You can sort an ArrayList by using the sort method of the Collecions class (java.util.Collections). Assuming you have an ArrayList called foo: Collections.sort(foo);


What advantage does the Java ArrayList class have over the Arrays class?

The biggest advantage of an ArrayList is that it can expand in size to fit more data. So, if you don't know how many data values you are going to have, you can construct an ArrayList. Whenever you use the add() method, the object will be added to the ArrayList, regardless of the current size. An Array does not have this advantage. When you construct an Array of size n, the array will always be that size.


What does the java new operator do?

The new keyword tells Java that you want to create a new instance of a class by invoking one of the constructors for that class.// Create a new, empty String objectString s1 = new String();// Create a new String object with a different constructorString s2 = new String("howdy");


What is subclasses in java?

Subclasses are classes that inherit from parent classes. i.e. ArrayList is a subclass of List.


What is exteranalizable in java?

Externalizable interface is a subclass of Serializable. Java provides Externalizable interface so as to give you more control over what is being serialized and what is not. Using this interface, you can Serialize only the fields of the class you want serialize and ignore the rest. This interface defines 2 methods: readExternal() and writeExternal() and you have to implement these methods in the class that will be serialized. In these methods you'll have to write code that reads/writes only the values of the attributes you are interested in. Programs that perform serialization and deserialization have to write and read these attributes in the same sequence


What is reference data types in java?

A reference variable is used to refer to (or access) an object. A reference variable is declared to be of a specific type and that type can never be changed. Ex: ArrayList lst = new ArrayList(); The above line creates a reference variable lst which refers to an ArrayList object


Extension file for Java?

Java source files have the .java extension, compiled Java class files have the .class extension.


What is arraylist in collection framework?

The java.util.ArrayList class is one of the most commonly used of all the classes in the Collections Framework. Some of the advantages ArrayList has over arrays are • It can grow dynamically. • It provides more powerful insertion and search mechanisms than arrays. Let's take a look at using an ArrayList that contains Strings. A key design goal of the Collections Framework was to provide rich functionality at the level of the main interfaces: List, Set, and Map. In practice, you'll typically want to instantiate an ArrayList polymorphically like this: List myFirstArrayList = new ArrayList(); As of Java 5 you'll want to say List myFirstArrayList = new ArrayList(); This kind of declaration follows the object oriented programming principle of "coding to an interface", and it makes use of generics. We'll say lots more about generics in future, but for now just know that, as of Java 5, the syntax is the way that you declare a collection's type. (Prior to Java 5 there was no way to specify the type of a collection, and when we cover generics, we'll talk about the implications of mixing Java 5 (typed) and pre-Java 5 (untyped) collections.) In many ways, ArrayList is similar to a String[] in that it declares a container that can hold only Strings, but it's more powerful than a String[]. Let's look at some of the capabilities that an ArrayList has List test = new ArrayList(); String s = "hi"; test.add("string"); test.add(s); test.add(s+s); System.out.println(test.size()); System.out.println(test.contains(42)); System.out.println(test.contains("hihi")); test.remove("hi"); System.out.println(test.size()); which produces 3 false true 2 There's lots going on in this small program. Notice that when we declared the ArrayList we didn't give it a size. Then we were able to ask the ArrayList for its size, we were able to ask it whether it contained specific objects, we removed an object right out from the middle of it, and then we rechecked its size.


How do you use arraylist in java programming?

The java.util.ArrayList class is one of the most commonly used of all the classes in the Collections Framework. Some of the advantages ArrayList has over arrays are • It can grow dynamically. • It provides more powerful insertion and search mechanisms than arrays. Let's take a look at using an ArrayList that contains Strings. A key design goal of the Collections Framework was to provide rich functionality at the level of the main interfaces: List, Set, and Map. In practice, you'll typically want to instantiate an ArrayList polymorphically like this: List myFirstArrayList = new ArrayList(); As of Java 5 you'll want to say List myFirstArrayList = new ArrayList(); This kind of declaration follows the object oriented programming principle of "coding to an interface", and it makes use of generics. We'll say lots more about generics in future, but for now just know that, as of Java 5, the syntax is the way that you declare a collection's type. (Prior to Java 5 there was no way to specify the type of a collection, and when we cover generics, we'll talk about the implications of mixing Java 5 (typed) and pre-Java 5 (untyped) collections.) In many ways, ArrayList is similar to a String[] in that it declares a container that can hold only Strings, but it's more powerful than a String[]. Let's look at some of the capabilities that an ArrayList has List test = new ArrayList(); String s = "hi"; test.add("string"); test.add(s); test.add(s+s); System.out.println(test.size()); System.out.println(test.contains(42)); System.out.println(test.contains("hihi")); test.remove("hi"); System.out.println(test.size()); which produces 3 false true 2 There's lots going on in this small program. Notice that when we declared the ArrayList we didn't give it a size. Then we were able to ask the ArrayList for its size, we were able to ask it whether it contained specific objects, we removed an object right out from the middle of it, and then we rechecked its size.