Solved

Differences between an Array and Collection

Posted on 2006-11-22
5
3,867 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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
custom annotations 9 38
iterator/ListIterator approach 17 26
Java string replace 11 45
Java Restore security prompts not working 10 10
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This video teaches viewers about errors in exception handling.

770 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