Results 1 to 6 of 6

Thread: Editing subject of a Hashtable

  1. #1
    Join Date
    Dec 2009
    Posts
    213

    Editing subject of a Hashtable

    Hello,
    I have a list of objects in the Hashtable and I must change as a routine field (if field = a, then replace with "String", if = b. ..). This field is also a list (ArrayList). Hashtable containing "Subject". Object containing an ArrayList Attributes. Attribute containing a type field to edit. The problem is that I travel with my lists of nested loops, I get my item, modify it, but this change is not reflected in the object stored in my Hashtable. If I add the object, he will not write another. it's just the bins. Someone had a solution for this problem ...?

  2. #2
    Join Date
    Nov 2009
    Posts
    335

    Re: Editing subject of a Hashtable

    Hello,
    This topic is new to me, but still I have a code with me, check out if it works
    Code:
    for (Iterator it = listeObjets.values().iterator(); It.hasNext();) {
                    Object obj = (Subject) it.next();
    	for(Iterator it2 = (obj.getLesAttributs()).iterator(); it2.hasNext();)
                    {
    		Attribute at =(Attribute)it2.next();
    String tp =(String) lesTypes.get(at.getType());
    at.setType(tp);
    	}
    	for(Iterator it2 =(obj.getLesMethodes()).iterator(); it2.hasNext();) 
                   {
    		Method meth =(Method)it2.next();
    String rt =(String)lesTypes.get(Meth.getRetour());
    Meth.setRetour(rt);
    					
    		for(Iterator it3 =(Meth.getLesParametres()).iterator(); it3.hasNext();){
    			Attribute at =(Attribute)it3.next();
    String tp =(String)lesTypes.get(at.getType());
    at.setType(tp);
    		}
    	}
    }

  3. #3
    Join Date
    Nov 2009
    Posts
    583

    Re: Editing subject of a Hashtable

    Hello,
    The code that we propose you seems correct and after testing my home, it works. Are you sure your applications through this snippet? are you sure the lists are not empty? Only changes to objects associated attribute does not work, or as that of Method objects? Can you put a trace in the methods setType () and setRetour () to see if they fit right in and what is the parameter that receives, at last check if the assignment goes well, (view before / after)?

  4. #4
    Join Date
    Nov 2009
    Posts
    446

    Re: Editing subject of a Hashtable

    Hello,
    I also tested and no problems but I have simulated the setter. Can you show us your setter you ... because according to the instructions that you do in your setters you do not work on the elements contained in your Hashtable with the iterator you do not work by reference. If you need any more help with it, then please do ask and we will try to help sort your problem.

  5. #5
    Join Date
    Dec 2009
    Posts
    213

    Re: Editing subject of a Hashtable

    Hello,
    In fact, I build my objects call methods of successive and therefore I have declared my items locally and that there is only one object instance. So I solved the problem by recreating a new object when the insert in the list, and by transferring the info from my purpose built in the new. Anyway, thank you for your help.

  6. #6
    Join Date
    Dec 2009
    Posts
    202

    Re: Editing subject of a Hashtable

    Hey,
    Even I am trying this section of java, and I have a example just have a look at it
    Code:
    Map mp = new HashMap();    
        mp = new TreeMap();        // sorted mp
        
        // Add key/val pairs to the mp
        mp.put("x", new Integer(1));
        mp.put("y", new Integer(2));
        mp.put("z", new Integer(3));
        
        // Get number of entries in mp
        int size = mp.size();        // 2
        
        // Adding an entry whose key exists in the mp causes
        // the new val to replace the old val
        Object odval = mp.put("x", new Integer(9));  // 1
        
        // Remove an entry from the mp and 
        // return the val of the removed entry
        odval = mp.remove("c");  // 3
        
        // Iterate over all keys in the table 
        Iterator it = mp.keySet().iterator();
        while (it.hasNext()) {
            // Retrieve key
            Object key = it.next();
        }
        
        // Iterate over all vals in table 
        it = mp.vals().iterator();
        while (it.hasNext()) {
            // Get val
            Object val = it.next();
        }

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. 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. C# Hashtable vs list vs dictionary
    By Zaafir in forum Software Development
    Replies: 3
    Last Post: 31-07-2009, 12:36 PM

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,713,993,065.92090 seconds with 17 queries