wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes ArrayList vs java.awt.List Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "ArrayList vs java.awt.List" Watch "ArrayList vs java.awt.List" New topic
Author

ArrayList vs java.awt.List

Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

What class does ArrayList belong to? I was trying to find it in the API Specs but couldn't. I am needing to find out what the different is between an ArrayList and java.awt.List other than the fact that java.awt.List is a component.
If you don't draw it, do they work the same??
Advantages, disadvantages to both?
------------------
Happy Coding,
Gregg Bolinger


GenRocket - Experts at Building Test Data
Paul Stevens
Ranch Hand

Joined: May 17, 2001
Posts: 2823
java.util
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521

public class ArrayList
extends AbstractList
implements List, Cloneable, Serializable
Resizable-array implementation of the List interface. Implements all optional list operations, and permits all elements, including null. In addition to implementing the List interface, this class provides methods to manipulate the size of the array that is used internally to store the list. (This class is roughly equivalent to Vector, except that it is unsynchronized.)
The size, isEmpty, get, set, iterator, and listIterator operations run in constant time. The add operation runs in amortized constant time, that is, adding n elements requires O(n) time. All of the other operations run in linear time (roughly speaking). The constant factor is low compared to that for the LinkedList implementation.
Each ArrayList instance has a capacity. The capacity is the size of the array used to store the elements in the list. It is always at least as large as the list size. As elements are added an ArrayList, its capacity grows automatically. The details of the growth policy are not specified beyond the fact that adding an element has constant amortized time cost.
An application can increase the capacity of an ArrayList instance before adding a large number of elements using the ensureCapacity operation. This may reduce the amount of incremental reallocation.
Note that this implementation is not synchronized. If multiple threads access an ArrayList instance concurrently, and at least one of the threads modifies the list structurally, it must be synchronized externally. (A structural modification is any operation that adds or deletes one or more elements, or explicitly resizes the backing array; merely setting the value of an element is not a structural modification.) This is typically accomplished by synchronizing on some object that naturally encapsulates the list. If no such object exists, the list should be "wrapped" using the Collections.synchronizedList method. This is best done at creation time, to prevent accidental unsynchronized access to the list:
List list = Collections.synchronizedList(new ArrayList(...));

The iterators returned by this class's iterator and listIterator methods are fail-fast: if list is structurally modified at any time after the iterator is created, in any way except through the iterator's own remove or add methods, the iterator will throw a ConcurrentModificationException. Thus, in the face of concurrent modification, the iterator fails quickly and cleanly, rather than risking arbitrary, non-deterministic behavior at an undetermined time in the future.

Since:
JDK1.2
See Also:
Collection, List, LinkedList, Vector, Collections.synchronizedList(List), Serialized Form

From http://java.sun.com/products/jdk/1.2/docs/api/index.html


"JavaRanch, where the deer and the Certified play" - David O'Meara
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
You will need to check the API for more details.
Java.util.List is different from java.awt.List
ArrayList is a class in the java.util package. It imlements the List interface in the same package. It's a collection, and is used for storing just about anyting (it accepts an object). Java.awt.List is a GUI component that.

Bosun


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Thanks a mil for all the responses!!!
Cindy - I did not get an E-mail telling me someone responded to this discussion. And I did select that option. Who do I need to contact about that? If you know that is..
Thank again everyone!!

------------------
Happy Coding,
Gregg Bolinger
Paul Stevens
Ranch Hand

Joined: May 17, 2001
Posts: 2823
Gregg in case you didn't know,
If you have the API on your hard-drive, use the jdk\docs\api\index.html. This has 3 frames. The top left all packages. The bottom left all classes (makes it easy to find when you don't know the package). The rest contains the actual class api.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Thanks Paul. I had actually found it minutes before I got the responses. I do have the API on my HD. Makes life so much easier that way.
Thanks again!!

------------------
Happy Coding,
Gregg Bolinger
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Gregg,
If you think that there is a problem with this forum or you just want to whine a bit, go to the JavaRanch forum and complain away.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

It seems to be working. I didn't want to whine or complain, just wanted to give whoever a heads up if something was wrong with the system.
Thanks

------------------
Happy Coding,
Gregg Bolinger
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
I know, but the rest of us like to whine over there sometimes. Keeps the forums less grumpy .
 
Consider Paul's rocket mass heater.
 
subject: ArrayList vs java.awt.List