• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

what is the use of different collections..

 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

Anybody please tell me what is the use of different collections..

when we use ArrayList, when we use Vector, When we use TreeMap, when we use HashMap, when we use Hashtable, when we use Arrays.


please explain.


Please reply

Thanks
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to Java In General (Intermediate) where you will, no doubt, be told that the best way to find out about the collection classes is to read the API.
http://java.sun.com/j2se/1.5.0/docs/api/index.html
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
when we use ArrayList, when we use Vector, When we use TreeMap, when we use HashMap, when we use Hashtable, when we use Arrays.

1. Never use Vector; always use ArrayList instead. Vector is an old class, left over from Java version 1.1. The main difference between Vector and ArrayList is that Vector is synchronized, while ArrayList is not. That makes ArrayList faster.

2. TreeMap or HashMap: Both are dictionary data structures; they allow you to store key-value pairs, and you use the keys to find the values. HashMap is unordered. In a TreeMap, elements are sorted on the keys. Sometimes that is useful in applications.

3. Hashtable: The same as with Vector; this is an old Java 1.1 class. Don't use it; use HashMap instead.

4. Arrays: An array has a fixed size. If you need a list that can grow or shrink dynamically (i.e., while the program is running), you'll need to use one of the implementations of java.util.List instead of an array.

Look here for more information: The Collections Framework
 
Ranch Hand
Posts: 1847
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
crossposted in just about every Java forum I know...
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Crib Sheet
 
Ranch Hand
Posts: 74
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jesper de Jong wrote:when we use ArrayList, when we use Vector, When we use TreeMap, when we use HashMap, when we use Hashtable, when we use Arrays.

1. Never use Vector; always use ArrayList instead. Vector is an old class, left over from Java version 1.1. The main difference between Vector and ArrayList is that Vector is synchronized, while ArrayList is not. That makes ArrayList faster.

2. TreeMap or HashMap: Both are dictionary data structures; they allow you to store key-value pairs, and you use the keys to find the values. HashMap is unordered. In a TreeMap, elements are sorted on the keys. Sometimes that is useful in applications.

3. Hashtable: The same as with Vector; this is an old Java 1.1 class. Don't use it; use HashMap instead.

4. Arrays: An array has a fixed size. If you need a list that can grow or shrink dynamically (i.e., while the program is running), you'll need to use one of the implementations of java.util.List instead of an array.



Great!! explanation Jesper, its really more valuable statements whatever you posted here, it'll help to understand the actual use of those for both who is learning java and also for them who's just started to work on the projects..actually some more points i also learnt from this thread..so thank you very much Jesper for this post.

__________________________________________________________________________________________________________________
-vivek
 
My favorite is a chocolate cupcake with white frosting and tiny ad sprinkles.
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