• 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
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Vector - Collection - ArrayList

 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
What is the difference between a vector, a collection and an arraylist.
I was wondering what the difference is in performance, or the easiest to use with when implementing code.
Greeting,
Roul
 
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A "Vector" is a legacy collection which you probably shouldn't use, unless other legacy code requires you to.
A "collection" is a general term to describe groups of objects, and could include arrays, Vectors, Lists, Sets etc. A java.util.Collection is the interface which all colletion implementations in the JDK use.
An ArrayList is one flavour of avaliable Collection, an implementation of the List interface. It is designed to hold growable sequences of data.
As far as performance goes, each Collection has its pros and cons. For example an ArrayList will give you rapid random access to elements, but will be slower than other Collections for inserts and updates; whereas a LinkedList will be better for insertions and deletions, but slower for random access.
Performance is not the main issue when using most Collections, rather what type of data you are storing: a group of object which are all unique? Use a Set. A group of objects which are sequential? Use a List. A group of objects which are key:value pairs? Use a Map.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic