This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

please tell me

 
manohar reddy
Greenhorn
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What are the differences between an �Object Array� and an �ArrayList�
 
colton peterson
Ranch Hand
Posts: 97
Linux Python VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Nacho Espinosa
Ranch Hand
Posts: 30
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Array Object always has a size.

And ArrayList size grows dinamically.

The size is not "important" for ArrayList.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47292
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 457
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rob Spoor
Sheriff
Pie
Posts: 20388
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic