• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

please tell me

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What are the differences between an �Object Array� and an �ArrayList�
 
Ranch Hand
Posts: 97
Python VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Array Object always has a size.

And ArrayList size grows dinamically.

The size is not "important" for ArrayList.
 
Marshal
Posts: 79808
388
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 457
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 22810
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Who among you feels worthy enough to be my best friend? Test 1 is to read this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic