Hashtable<String, Hashtable<String, HashSet<String>>> test =
new Hashtable<String, Hashtable<String, HashSet<String>>>();
test.put("1", new Hashtable<String, HashSet<String>>());
Hashtable<String, HashSet<String>> actual = test.get("1");
actual.put("3", new HashSet<String>());
//test.put("1", actual);
HashSet<String> expected = test.get("1").get("3");
if ( ...
|
I just need to return the largest value in a Hashtable:
Hashtable<String,Integer> h = new Hashtable<String,Integer>();
h.add( "a",1 );
h.add( "b",5 );
h.add( "c",3 );
h.add( "d",5 );
h.add( "e",2 );
h.add( "f",1 );
int max = ???;
I just ... |
I have a hashtable, which contains strings for example, when I use put method as below
hashtable.put("1","A");
hashtable.put("1","B");
hashtable.put("1","C");
hashtable.put("1","D");
hashtable.put("1","E");
Then when I try to print it back it doesn't ... |
I have 2 hashtables. htPartFromDB and htPartFromSheet.
htPartFromDB will fetch all the parts from the table in sql db and store it as key and value being the id.
htPartFromSheet will fetch ... |
Question on hashtables. I have a hashtable called Caplimits. In my code I am trying to extract from the hashtable the value (attribute) if the entity passed in matches the key. Is there a way to do that in my getCaplmts method because I am getting this error: Type mismatch: cannot convert from Object to BigDecimal? Any help or direction would ... |
hi all, i am storing string array as keys and arraylist as values in my hashtable.when i retrieving the values at particular keys am getting values of last key index to all of my key values.that means the last key values(arraylist)are reflected to all while displaying.can anyone help regarding this Thanks & regards, Murali |
|
|
|
|
I think the more important question is: why would you NOT want to allow null keys and values? Using null values for defaults (if there is no value for a non-null key, check the value for the null key) isn't uncommon. If you want to disallow them, use Collections.checkedMap - that one forbids null as well. |
Hi, Sorry for the mistake. What I meant was that I have a class which maintains a hashtable. Another class in the same package running on the same JVM tries to add data to that hashtable. There are like many instances of the second class and all they do is just add data to the hashtable. Please suggest a way of ... |
Hi, thank you all for your replies, but i still have doubts regarding null values in hash table. i have entered null as key and when i use get("null"), the value that is paired to null key is being displayed. for your reference am giving the code and output here. import java.util.Hashtable; import java.util.Enumeration; import java.util.Set; import java.util.Iterator; public class HashTableDemo ... |
|
hey guys, i need some help with my code: //i have a seperate constructor for the profile type Profile userProfile = new Profile(); public static Hashtable table1 = new Hashtable(10, 0.75f); table1.put(name, userProfile); now, the insertion seems to work fine, i can use remove(name) to remove from the hash table and it works flawlessly. But, to get the value out of ... |
Is this a joke? Why are you turning the strings into dates, and then back into strings again?. Even if the strings at both ends of the process are identical, it's a strange thing to do. You should key the hashtable off of the Date objects. Other issues: You're using a deprecated constructor for Date. Use java.text.SimpleDateFormat to parse the date ... |
|
Hi all, I am kinda new to working with hashtables, which is why I have this question. I am trying to replace an already existing value in a hashtable with a new value, while keeping the index same.. the command i am using is put(); is there any other command for this specific purpose, like replace()? I could not find anything ... |
"first element" means the first element added to the Hashtable. "second element" means the second element added to the Hashtable. I don't want to alter the order of elements. If I re-order the elements, I will change the order they were added in. I just want to change the values so that it reflects their corresponding order. |
Great thread! The original question doesn't make sense and it attracts all sorts of utterly wrong remarks and 'answers' (mind the quotes). How long will this go on? spoiler: a Hashtable, nor a HashMap, nor any Map nor Set can contain duplicate values so there is no need to attempt to remove them. king regards, Jos |
|
|
|
|
if(ProcessNameMap.containsKey(QueueConstants.SENDUX_QUEUELIST)) { java.util.ArrayList QueueNameInProcessDab2 = (java.util.ArrayList) ProcessNameMap.get(QueueConstants.SENDUX_QUEUELIST); java.util.Iterator it12 = QueueNameInProcessDab2.iterator(); while (it12.hasNext()) { String QueueName = (String) it12.next(); QueueNamesInProcessini.add(QueueName); } } if(ProcessNameMap.containsKey(QueueConstants.RECV_QUEUELIST)) { java.util.ArrayList QueueNameInProcessDab3 = (java.util.ArrayList) ProcessNameMap.get(QueueConstants.RECV_QUEUELIST); java.util.Iterator it13 = QueueNameInProcessDab3.iterator(); while (it13.hasNext()) { String QueueName = (String) it13.next(); QueueNamesInProcessini.add(QueueName); } } /*java.util.Iterator it32 = QueueNamesInProcessini.iterator(); while (it32.hasNext()) { String QueueDetailName = (String) it32.next(); System.out.println(QueueDetailName); }*/ |
Now I have two hash tables. Hashtable h = new Hashtable(); Hashtable ht = new Hashtable(); One Hastable contains some values h.put("Sun Java", "sun"); h.put("forum.java" , "java forum"); Enumeration k = h.keys(); while (k.hasMoreElements()) { String key = (String) k.nextElement(); System.out.println("Hast Table h"); System.out.println("Key " + key + "; Value " + (String) h.get(key)); } Enumeration k1 = ht.keys(); while (k1.hasMoreElements()) ... |