Solved

Differences between an Array and Collection

Posted on 2006-11-22
5
3,864 Views
Last Modified: 2008-01-09
May i know what is the differences between an Array and Collection? Thank you.
0
Comment
Question by:retkehing
  • 2
5 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 17997057
An array is inherently fixed in size, whereas a Collection can grow. That's the most important difference
0
 
LVL 24

Accepted Solution

by:
sciuriware earned 30 total points
ID: 17997850
And: in an array the values are side by side,
a collection will scatter the values to positions where they are most convenient.
Every collection has its pro's and con's.
E.g.: linked lists can insert an item quickly but are a drag to sort.

;JOOP!
0
 
LVL 6

Expert Comment

by:SamsonChung
ID: 17999157
Arrays a basic structures. for example, an array of integers means every single insert in there is an integer.

while in collection, you don't have that limitation.

you can have first object being an integer, 2nd being a String, 3rd being a string, 4th being an INTEGGER..

noticed, string and INTEGGER are not typos, they are custom classes you can define.

0
 
LVL 24

Expert Comment

by:sciuriware
ID: 18001058
SamsonChung, what would you say about this code piece?

     Object[] array = new Object[4];

     array[0] = "12345";
     array[1] = new Integer(6);
     array[2] = new Exception("Also!");
     array[3] = this;

???

;JOOP!
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now