Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

please tell me

 
manohar reddy
Greenhorn
Posts: 12
  • 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
  • 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
  • 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: 48981
60
  • 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
  • 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: 20533
54
Chrome Eclipse IDE Java Windows
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic