Hash Maps


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Hash Maps

  1. #1
    Join Date
    Nov 2005
    Posts
    18

    Unhappy Hash Maps

    Hi i quite new to java and am currently having a problem with Hashmaps,

    I have stored an object called Users in a Hashmap called clients, i am then trying to return the object based on the its ID and pass it into a temp Users object so i might use the methods.

    The current error message is incompatable types..
    Here is some of my code...

    Map Clients = new HashMap();

    Clients.put(UserName, new Users(UserName, Password, IP, PortNo));
    Users User3 = new Users();
    User3=Clients.get(UserName);*Error

    Is there a simple soultion to this?
    Thanks in Advance.

  2. #2
    Join Date
    Aug 2003
    Posts
    313
    If you are getting a compile-time error, just insert a cast to cast Client.get(UserName) to be of type user. e.g.
    Code:
    User3 = (Users) Client.get(UserName);
    Hope this helps.
    ~evlich

  3. #3
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    Clients.put(UserName, new Users(UserName, Password, IP, PortNo)); // ok
    Users User3 = new Users(); // no need for this statement
    Users User3=(Users)Clients.get(UserName); // you must typecast, get returns Object
    Last edited by sjalle; 12-10-2005 at 11:28 AM.
    eschew obfuscation

  4. #4
    Join Date
    Nov 2005
    Posts
    18
    Brilliant, thanks guys, seems to have done the trick!

Similar Threads

  1. need help for Hash Function in Java
    By alirazvi in forum Java
    Replies: 0
    Last Post: 08-18-2005, 11:43 AM
  2. suggest tutorial for maps.
    By swapnil_paranja in forum C++
    Replies: 1
    Last Post: 08-08-2005, 08:15 AM
  3. Replies: 10
    Last Post: 04-06-2005, 05:30 PM
  4. Re: Looking for some magic . . . With Hashing
    By Patrick Ireland in forum .NET
    Replies: 0
    Last Post: 08-02-2001, 05:22 PM
  5. Replies: 0
    Last Post: 04-17-2001, 03:20 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center