Results 1 to 6 of 6

Thread: Hashtable vs Vector

  1. #1
    Join Date
    Dec 2009
    Posts
    192

    Hashtable vs Vector

    Hello,
    What is the best performance among a class vector containing obj x htable and contain the same objects x? I want the difference between the HashTable and Vector.

    a) Viewpoint memory footprint)
    b) Find item (s)
    c) Runtime

    For my part:
    a) No idea
    b) The class vector should be optimized for this type of research though?
    c) No idea also

    If you have any idea about this then please help me. Thanks in advance.

  2. #2
    Join Date
    Nov 2009
    Posts
    356

    Re: Hashtable vs Vector

    Hello,
    Already not the same use. A HashTable allows you to assign a key to an object in order to retrieve the object later from the key, not the Vector . What you should know also that level perfect c Vector is threadsafe, therefore, I tend to think that there are unnecessary things in a single thread application and it is better to use something else. Hope you understand what I am trying to explain you.

  3. #3
    Join Date
    Nov 2009
    Posts
    335

    Re: Hashtable vs Vector

    Hello,
    A hashtable is indexed by the keys it logically faster than a vector. A hastable is a way to map a value to a key so that a vector is a "simple" table, his interest in relation to other classes (ArrayList com) is that you can access the elements via an index.
    a) it must not be a big diff
    b) hashtable is better if you have a key
    c) probably because the hashtable elements are indexed so searching is faster

  4. #4
    Join Date
    Nov 2009
    Posts
    330

    Re: Hashtable vs Vector

    Hello,
    I would like to add to the above post, remember that even though Vector is inefficient, you can improve it in the constructor specifying a starting size and then specifying a size increase when it becomes too small. Indeed, vector can not know what it will contain. For example, if you know that you should always contain fewer than 100 instances then create a vector 100 of the departure, if more than 100 overtaking is rare, then gives a small increment of value. Moreover, these settings allow you to better manage the RAM occupied.

  5. #5
    Join Date
    Nov 2009
    Posts
    446

    Re: Hashtable vs Vector

    Hello,
    Unless you do want to maintain compatibility with older JVM (below version 1.2) is preferable to use the collection framework even in a multi-threaded application:
    Code:
    List lst = Collections.synchronizedList ( new ArrayList() );
    Map mp = Collections.synchronizedMap ( new HashMap() );
    But a Vector (ArrayList) corresponds to a Java array, then indexed by integers, which should be faster I think. Quite agree! It may be better for you to tell us what you gonna do. By cons, there is not much of interest to compare the List and Map.

  6. #6
    Join Date
    Dec 2009
    Posts
    192

    Re: Hashtable vs Vector

    Hello,
    So what I want to realize is a jtree the data from my database. So each data contains an id, parent id and a text that I put in a class nodeInfo. I put the class in a DefaultMutableTreeNode is going to put in my tree but also in a vector or hastable I know yet. Then my tree is complement default mutable TreeNode which content of nodeInfo and if I do not change a node bin, I need to know to find the class so I would use a node Info hastable or vector. So if I add nodes must be capable of hastable accept the space in his memory that the vector would very well.

Similar Threads

  1. HashMap vs HashTable
    By Joyjeet in forum Software Development
    Replies: 6
    Last Post: 04-01-2011, 09:07 PM
  2. Editing subject of a Hashtable
    By Aaliya Seth in forum Software Development
    Replies: 5
    Last Post: 23-02-2010, 04:38 AM
  3. Manipulating a hashtable
    By Miles Runner in forum Software Development
    Replies: 5
    Last Post: 12-02-2010, 01:20 AM
  4. Problem sorting a Hashtable
    By Vodka in forum Software Development
    Replies: 5
    Last Post: 04-02-2010, 05:16 AM
  5. How to use hashtable to replace content
    By RasMus in forum Software Development
    Replies: 3
    Last Post: 27-07-2009, 10:30 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,012,274.27968 seconds with 17 queries