Results 1 to 1 of 1
  1. #1
    peterdfl is offline Member
    Join Date
    Mar 2008
    Posts
    8
    Rep Power
    0

    Question Searching

    I need to sort a file numbers into an array then make a hash table of the values.

    Java Code:
       // Create a hash table
        Map map = new HashMap();    // hash table
        map = new TreeMap();        // sorted map
        
        // Add key/value pairs to the map
        map.put("a", new Integer(1));
        map.put("b", new Integer(2));
        map.put("c", new Integer(3));
        
        // Get number of entries in map
        int size = map.size();        // 2
        
        // Adding an entry whose key exists in the map causes
        // the new value to replace the old value
        Object oldValue = map.put("a", new Integer(9));  // 1
        
        // Remove an entry from the map and return the value of the removed entry
        oldValue = map.remove("c");  // 3
        
        // Iterate over the keys in the map
        Iterator it = map.keySet().iterator();
        while (it.hasNext()) {
            // Get key
            Object key = it.next();
        }
        
        // Iterate over the values in the map
        it = map.values().iterator();
        while (it.hasNext()) {
            // Get value
            Object value = it.next();
        }
    Last edited by peterdfl; 12-15-2008 at 05:43 PM. Reason: title

Similar Threads

  1. Hashing in Java
    By ajaykushwaha in forum New To Java
    Replies: 1
    Last Post: 11-17-2008, 01:51 PM
  2. Problem with searching while using GUI
    By BHCluster in forum AWT / Swing
    Replies: 1
    Last Post: 04-24-2008, 07:56 PM
  3. Searching an arraylist
    By adelgado0723 in forum New To Java
    Replies: 1
    Last Post: 04-15-2008, 02:09 PM
  4. Hash table with double hashing
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-12-2008, 09:43 PM
  5. searching
    By nalinda in forum New To Java
    Replies: 3
    Last Post: 12-06-2007, 03:56 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •