|
| |||||||||
| Tags: hasmap, hasttable, java, map, programming language, table, utilties |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| 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
| |||
| |||
| 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
| |||
| |||
| 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
| |||
| |||
| 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
| |||
| |||
| 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
| |||
| |||
| 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();
} |
![]() |
|
| Thread Tools | Search this Thread |
| |
Similar Threads for: "Editing subject of a Hashtable" | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| HashMap vs HashTable | Joyjeet | Software Development | 6 | 04-01-2011 09:07 PM |
| Hashtable vs Vector | Vodka | Software Development | 5 | 23-02-2010 02:43 AM |
| Manipulating a hashtable | Miles Runner | Software Development | 5 | 12-02-2010 01:20 AM |
| Problem sorting a Hashtable | Vodka | Software Development | 5 | 04-02-2010 05:16 AM |
| C# Hashtable vs list vs dictionary | Zaafir | Software Development | 3 | 31-07-2009 01:36 PM |