aspose file tools*
The moose likes Beginning Java and the fly likes please tell me Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "please tell me" Watch "please tell me" New topic
Author

please tell me

manohar reddy
Greenhorn

Joined: Oct 13, 2007
Posts: 12
What are the differences between an �Object Array� and an �ArrayList�
colton peterson
Ranch Hand

Joined: Nov 18, 2007
Posts: 97

I'm no expert but an object array is just a normal array and a arrayList is a class in java.util. it is like an array but it can grow in size.


www.mormon.org
Nacho Espinosa
Ranch Hand

Joined: Jan 17, 2007
Posts: 30
The Array Object always has a size.

And ArrayList size grows dinamically.

The size is not "important" for ArrayList.


Greetings<br />Nacho Espinosa<br />SCJP 1.4
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39784
    
  28
That sounds correct, but be careful to spell it ArrayList not arrayList.
There is a lot more to ArrayList than that; it has all the methods of the java.util.List interface, as well as the ensureCapacity method. It actually has an array at its heart. It doesn't really change its size, but whenever you need more storage space, the array is replaced by a similar but larger array. Not surprisingly, it is probably the most popular class in the collections framework.

Beware: Tiny point to take notice of. I think the toList() method of java.util.Arrays returns something called ArrayList, but it is actually a different class.
Bill Shirley
Ranch Hand

Joined: Nov 08, 2007
Posts: 457
What are the differences between an �Object Array� and an �ArrayList�


For the answer to the unasked question "why":

In the beginning, there was C. It hid the machine. It was procedural. It had the basic types (int, char, array, *(pointer) ...)

Java went object oriented, tossed out the pointer, and added Object. It also added a small class library.

java.util.ArrayList was a wrapper for the base type array, just as Integer wraps int.

A good rule of thumb for a beginner, use Collection/Set/List/ListArray if you're making the decision, not the array. If you run into an array you have to use,... come back for help.


Bill Shirley - bshirley - frazerbilt.com
if (Posts < 30) you.read( JavaRanchFAQ);
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19759
    
  20

Originally posted by Campbell Ritchie:
Beware: Tiny point to take notice of. I think the toList() method of java.util.Arrays returns something called ArrayList, but it is actually a different class.

It's called asList(), but you are correct. This class is called java.util.Collections.ArrayList, which is not accessible except when using the asList() method. The one you usually use is java.util.ArrayList.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: please tell me