Results 1 to 6 of 6

Thread: Manipulating a hashtable

  1. #1
    Join Date
    Dec 2009
    Posts
    292

    Manipulating a hashtable

    Hello,
    I have a problem with my code, I am using hashtable and trying to manipulate the hashtable. I create the object and saves them in a hashtable that call collection.
    Code:
     collection.could(PMSN, PMSN.Getner().getId());
    / / PMSN is an instance of the object
    / / Getner (). getId () returns a string that represents the value of the key PMsn
    But the code is not working for me. I think I am missing something in my code, but I have no idea what. If you have any idea about it then please help me. Thanks in advance.

  2. #2
    Join Date
    Dec 2009
    Posts
    202

    Re: Manipulating a hashtable

    Hello,
    Even I am trying a similar kind of a coding , but successful yet. I have tried some thing in it. Here is the code of what I have done till now.
    Code:
    Public void locate(String idpc)
         {
              System.out.System.out.println("I am");
     
                if((StartUpSwing.Collection.containsValue("124ad")) == true)
    / / "124ad" exists in the hashtable (I checked because I serialize and deserialize Hashtable in the launch of the application
                {
    
                    System.out.System.out.println("c bon") ;
                }

  3. #3
    Join Date
    Nov 2009
    Posts
    356

    Re: Manipulating a hashtable

    Hello,
    To see your first code block, I think you reverse "key" and "value". I would see instead.
    Code:
    / * Put (key, value) and not vice versa * /
    collection.could(PMSN.Getner().getId(), PMSN);
    Then, knowing that there is a Collection interface in Java, call your HashTable "collection" is in my view, a source of potential error, so to avoid. In what version of Java code you are programming in? IF you are using JAVA 1.4 or higher, it is better to focus on a HashMap to a Hashtable.

  4. #4
    Join Date
    Nov 2009
    Posts
    359

    Re: Manipulating a hashtable

    Hello,
    I agree with the above posted. The following two lines are strictly equivalent, uses-rather then the 2nd, which saves an operation and is clearer.
    Code:
    (StartUpSwing.Collection.containsValue("test")) == true;
    (StartUpSwing.Collection.containsValue("test"))
    When searching an object indexed by a key in a Hashtable (or HashMap), it performs research on the key:
    Code:
    if(StartUpSwing.Collection.containsKey("test")) { /* ..... */ }
    I hope you get the point what I am trying to explain you.

  5. #5
    Join Date
    Dec 2009
    Posts
    292

    Re: Manipulating a hashtable

    Hello,
    I have tried the thing which are above posted.
    Code:
    Public void locate(String idpc)  
    {  System.out.System.out.println("I am");
       if((StartUpSwing.Collection.containsKey("test")) == true) / / "test" exists in the hashtable (I checked because I serialize and deserialize Hashtable in the launch of the application 
     {   System.out.System.out.println("c bon") ; }
    It gives me but I am not in that, it has not come back because he can not find the key. Yet it is well established as my file I found it well my item.

  6. #6
    Join Date
    Nov 2009
    Posts
    446

    Re: Manipulating a hashtable

    Hello,
    I think it is better to do a search on the key value.
    Code:
       if((StartUpSwing.Collection.containsKey("test")) )
    You can use the above to do the same. If you want more information on this then you can visit the official site of the sun for the java api, there you will find all the method and classes used by java. If you have any more problem regarding this topic then please do post back.

Similar Threads

  1. HashMap vs HashTable
    By Joyjeet in forum Software Development
    Replies: 6
    Last Post: 04-01-2011, 09:07 PM
  2. Hashtable vs Vector
    By Vodka in forum Software Development
    Replies: 5
    Last Post: 23-02-2010, 02:43 AM
  3. Problem sorting a Hashtable
    By Vodka in forum Software Development
    Replies: 5
    Last Post: 04-02-2010, 05:16 AM
  4. C# Hashtable vs list vs dictionary
    By Zaafir in forum Software Development
    Replies: 3
    Last Post: 31-07-2009, 12:36 PM
  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,750,588,394.42256 seconds with 16 queries