answersLogoWhite

0

What is an Arraylist used for?

Updated: 8/10/2023
User Avatar

Wiki User

βˆ™ 10y ago

Best Answer

An ArrayList is a data structure. It stores data in an array that can be dynamically resized. This data structure in Microsoft .NET Framework contains Methods that assist the programmer in accessing and storing data within the ArrayList. The following link explains the .NET ArrayList class. http://msdn2.microsoft.com/en-us/library/system.collections.arraylist(vs.80).aspx

User Avatar

Wiki User

βˆ™ 16y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

βˆ™ 15y ago

java.util.ArrayList is a collection class that is used to hold a collection of objects.

ex: ArrayList lst = new ArrayList();

The above line creates a new ArrayList of name lst

You can add objects to it by using the add method.

Ex: lst.add(object);

An ArrayList can have any number of elements. You can get the object at a specified position by using the get method

Ex: Object obj = lst.get(1);

It is fast and easy to use.

Note: It is not thread safe so do not use them in multi-threaded programming. Use Vectors instead.

This answer is:
User Avatar

User Avatar

Wiki User

βˆ™ 10y ago

An Array List in Java is a way of structuring data and in one of several ways of structuring data. It cannot be dynamically resized and does not support search and sort while other data structures do.

This answer is:
User Avatar

User Avatar

Wiki User

βˆ™ 12y ago

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.

This answer is:
User Avatar

User Avatar

Wiki User

βˆ™ 12y ago

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

This answer is:
User Avatar

User Avatar

Wiki User

βˆ™ 12y ago

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

This answer is:
User Avatar

User Avatar

Wiki User

βˆ™ 10y ago

An Arraylist is used to store data and contains methods to help the programmer access and store data in an Arraylist. It has the ability to expand its size and make more room for more data.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is an Arraylist used for?
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.


How can you convert ArrayList to Vector?

Both of these types of Collections allow for a new instance to be created with the contents of another Collection. // This method will accept a Vector and return a new ArrayList which contains all elements of that Vector static ArrayList toArrayList(Vector v) { return new ArrayList(v); } // This method will accept an ArrayList and return a new Vector which contains all elements of that ArrayList static Vector toArrayList(ArrayList al) { return new Vector(al); }


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


How many number of objects we can store in an ArrayList. Is there any limit?

No. there is actually no such limit in any of the collections in java. The arraylist and vector are the most commonly used collections and they take thousands of objects. I have personally used them with atleast a 100,000 thousand objects.


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 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.


What happens when you pass an object as an argument to addAll fucntion of arraylist?

If the passed object extends Collection, then all the objects in collection are added to the arraylist.


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


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 are advantages of an arraylist?

ArrayList Features In Java Index based – Elements can be randomly accessed using index . Arraylist Index start with β€˜0’. Ordered – Elements maintain insertion ordered . Dynamic resizing – increase size dynamically when more elements needs to be added than it’ current size. Non synchronized – is not synchronized, by default.. Duplicates allowed – We can add duplicate elements . null value – Arraylist can store null values.


Can you serialize the ArrayList class in Java?

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.