answersLogoWhite

0


Best Answer

Just add the elements to the end of the ArrayList, and take them out from the end of the ArrayList. Use the .add() method to add an element to the end; use the .size() method to find out how many elements it has (so you can access the last element), and use the .remove() method to eliminate this last element.

User Avatar

Wiki User

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

Wiki User

βˆ™ 12y ago

Stack myStack = new Stack<Object>();

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you Implement a Stack using an ArrayList in java?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

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.


Can you provide a solution to the diamond-square algorithm using Java and recursion?

Yes. It is possible to provide a solution to the diamond-square algorithm using Java and recursion.


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


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


A stack can be implemented as?

One way to implement a stack is with a singly-linked list. The head pointer always points to the "top of the stack", and each element points to the next. Since you rarely, if ever, are interested in more than the top of the stack, this is one way, although not the most efficient way, to implement a dynamic stack.Since a stack is an abstraction, the best way to do this is to use a C++ abstract class or JAVA interface, as that would allow you to fine tune the implementation without having to think about the utilization. Since since the category did not specify C++ or JAVA, however, that ends that discussion.

Related questions

Write a java program to implement stack in java?

You would need an array to store the actual stack. Better use an ArrayList or some other structure that you can redimension. You'll also need a variable to point to the "top of stack" - the last element added, which is the first element to be taken away.


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.


Can you provide a solution to the diamond-square algorithm using Java and recursion?

Yes. It is possible to provide a solution to the diamond-square algorithm using Java and recursion.


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


Where can one find out how to implement threads using Java?

You can find out how to implement threads using Java through Stacker Overflow, Java Script Source, Java Code Geeks, Free Programming Resources and other websites. There are also tutorials on college sites as well as Youtube.


What is subclasses in java?

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


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


A stack can be implemented as?

One way to implement a stack is with a singly-linked list. The head pointer always points to the "top of the stack", and each element points to the next. Since you rarely, if ever, are interested in more than the top of the stack, this is one way, although not the most efficient way, to implement a dynamic stack.Since a stack is an abstraction, the best way to do this is to use a C++ abstract class or JAVA interface, as that would allow you to fine tune the implementation without having to think about the utilization. Since since the category did not specify C++ or JAVA, however, that ends that discussion.


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.


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