answersLogoWhite

0

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);

User Avatar

Wiki User

∙ 16y ago
User Avatar

What else can I help you with?

Continue Learning about Engineering

Can you store non primitive data type in the array list?

Yes you can store non primitive data type variables in an array. String is a non primitive data type. You can declare a string array as: String a[]=new String[10];


What is difference between array and class?

An array is a collection of the same type of data, for example, integers. Each element is accessed through an index - a numerical value. For example, myArray[x], where "x" is an integer variable.An object (created from a class) can store different types of data; each is accessed through its name, for example, person.age, person.name, etc.An object, or class, also has several other properties that distinguish it from an array; for example, classes/objects also have methods (functions defined at the class level), and with classes you can have inheritance.


Can you change the size of an array dynamically in Java?

Arrays are objects in Java that store multiple variables of the same type. Arrays can hold either primitives or object references, but the array itself will always be an object on the heap, even if the array is declared to hold primitive elements. In other words, there is no such thing as a primitive array, but you can make an array of primitives


Create a mark list using array with structure?

sorce code for student mark list usig array


Does a collection require an array?

No. While there are quite a few which use arrays to store their data (ArrayList, HashMap, Vector, etc.) the typical counter example is a LinkedList. Java's implementation of the LinkedList class uses the standard Entry-Entry.next method of connecting elements in the list. You can even consider a collection as something that is similar to an array but with enhanced features. Collections have a lot of features that arrays do not have.

Related Questions

Can you store non primitive data type in the array list?

Yes you can store non primitive data type variables in an array. String is a non primitive data type. You can declare a string array as: String a[]=new String[10];


How would you use the word array in a sentence?

An array is a list of data items or variables of the same type, like a list of numbers or a list of dates or a list of names.


Is there a way to create variables as needed in C based on user input?

Yes. You can store any number of values input at runtime using a variable-length array or any other sequence container such as a list.


What is difference between array and class?

An array is a collection of the same type of data, for example, integers. Each element is accessed through an index - a numerical value. For example, myArray[x], where "x" is an integer variable.An object (created from a class) can store different types of data; each is accessed through its name, for example, person.age, person.name, etc.An object, or class, also has several other properties that distinguish it from an array; for example, classes/objects also have methods (functions defined at the class level), and with classes you can have inheritance.


A travel agent wants a program to store an alphabetical list of winter holiday destinations State the most efficient way to store lists using a programming language?

The most efficient way to store a list is with an array.


Can you change the size of an array dynamically in Java?

Arrays are objects in Java that store multiple variables of the same type. Arrays can hold either primitives or object references, but the array itself will always be an object on the heap, even if the array is declared to hold primitive elements. In other words, there is no such thing as a primitive array, but you can make an array of primitives


What are some of the benefits of using an array as opposed to a medium-sized list of variables?

Arrays exist in contiguous memory, so you can use simple pointer arithmetic to access any element by its offset from the start address (the array name is an alias for the start address), and can pass the entire array to functions as a single entity. Lists of variables are not guaranteed to exist in contiguous memory, and cannot be passed to functions as a single entity.


What is array literal in as2?

An array literal is a comma-separated list of the elements of an array. An array literal can be used for initializing the elements of an array.


Create a mark list using array with structure?

sorce code for student mark list usig array


How does 'array names' command work in tcl?

In Tcl, the array names command is used to retrieve a list of all the keys (or indices) in a specified associative array. When you invoke array names arrayName, it returns a list containing the names of all elements in the array arrayName. If the array is empty, it returns an empty list. This command is useful for iterating over the elements of an array or for checking its contents.


Can linked list represent in array if yes show how insertion and deletions can perform in array representation of inked list?

yes


Does a collection require an array?

No. While there are quite a few which use arrays to store their data (ArrayList, HashMap, Vector, etc.) the typical counter example is a LinkedList. Java's implementation of the LinkedList class uses the standard Entry-Entry.next method of connecting elements in the list. You can even consider a collection as something that is similar to an array but with enhanced features. Collections have a lot of features that arrays do not have.