473,804 Members | 2,215 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

HashTable help

39 New Member
Hi,
i need one help in HashTable. see the below example
Expand|Select|Wrap|Line Numbers
  1. /*
  2.  * HashTableTest.java
  3.  *
  4.  * Created on October 20, 2007, 12:48 PM
  5.  *
  6.  * To change this template, choose Tools | Template Manager
  7.  * and open the template in the editor.
  8.  */
  9.  
  10. package kcbchatapplication;
  11.  
  12. import java.util.Hashtable;
  13. import java.util.Iterator;
  14.  
  15. /**
  16.  *
  17.  * @author nagaraj
  18.  */
  19. public class HashTableTest {
  20.  
  21.     /** Creates a new instance of HashTableTest */
  22.     private static Hashtable table;
  23.     public HashTableTest() {
  24.         table=new Hashtable();
  25.     }
  26.     private void AddTwo()
  27.     {
  28.         table.put("first","First");
  29.         table.put("second","Second");
  30.     }
  31.     private void AddThree()
  32.     {
  33.         table.put("three","Three");
  34.     }
  35.  
  36.     public static void main(String a[])
  37.     {
  38.         HashTableTest test=new HashTableTest();
  39.         test.AddTwo();
  40.       //  Enumeration en=table.elements();
  41.  
  42.         for (Iterator it=table.keySet().iterator(); it.hasNext(); ) {
  43.         Object key = it.next();
  44.         Object value = table.get(key);
  45.         System.out.println("Values:" +value.toString());
  46.          }
  47.  test.AddThree();
  48.    for (Iterator it1=table.keySet().iterator(); it1.hasNext(); ) {
  49.         Object key = it1.next();
  50.         Object value = table.get(key);
  51.         System.out.println("Values:" +value.toString());
  52.          }
  53.     /*    while(en.hasMoreElements())
  54.         {
  55.            System.out.println("Values:" +en.nextElement().toString());
  56.         }
  57.         test.AddThree();
  58.          Enumeration en1=table.elements();
  59.         while(en1.hasMoreElements())
  60.         {
  61.            System.out.println("Values:" +en1.nextElement().toString());
  62.         }*/
  63.     }
  64.  
  65.     public Hashtable getTable() {
  66.         return table;
  67.     }
  68. }
while running this example i get the out put like this,
Values:Second
Values:First
Values:Second
Values:Three
Values:First
But my need is,this will be look as following,
Values:Second
Values:First
Values:Second
Values:First
Values:Three

How to do that?
Regards,
Nags
Oct 20 '07 #1
3 1766
JosAH
11,448 Recognized Expert MVP
How to do that?
Regards,
Nags
Have a look at the LinkedHashMap class instead; a HashTable can't do what
you want it to do.

kind regards,

Jos
Oct 20 '07 #2
NagarajanS
39 New Member
hi,
Can any body give a a small example in linked hashtable?
Regards,
Nags
Oct 22 '07 #3
JosAH
11,448 Recognized Expert MVP
hi,
Can any body give a a small example in linked hashtable?
Regards,
Nags
Simply replace the HashTable references in your code by LinkedHashMap
references. Both classes are members of the Collections framework.

kind regards,

Jos
Oct 22 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

10
2834
by: Brian | last post by:
I'm reasonably new to C#, and using a class containing a hashtable collection to feed a treeview. My problem is that I can't pull the data from the hashtable! Here's the code I have: if (myItem.DataFields.Count != 0) foreach (string name in myItem.DataFields.Values) { treeView1.SelectedNode.Nodes.Add (name); // Error on this line }
5
2834
by: francois | last post by:
First of all I would to to apologize for resending this post again but I feel like my last post as been spoiled Here I go for my problem: Hi, I have a webservice that I am using and I would like it to return an XML serialized version of an object.
7
6892
by: Joseph Lee | last post by:
Hi All, I am having problem when i am using hashtable to keep an array of bytes value as keys. Take a look at the code snippet below --------------------------------------------------- ASCIIEncoding asciiEncoder = new ASCIIEncoding();
33
3326
by: Ken | last post by:
I have a C# Program where multiple threads will operate on a same Hashtable. This Hashtable is synchronized by using Hashtable.Synchronized(myHashtable) method, so no further Lock statements are used before adding, removing or iterating the Hashtable. The program runs in a high workload environment. After running a few days, now it suddenly catchs this Exception when inserting a pair of key and object, stacktrace =...
2
3859
by: Marek | last post by:
I am having a problem with Hashtable used in XML web server. I have a WebMethod where clients get registered and added into hashtable. Later, I call another web method which has client ID as parameter. I first thought I was doing something wrong with keys, but now i found out the Hashtable is empty (Count property returns 0) Code: public void RegisterClient(int id)
3
1142
by: bernardpace | last post by:
Hi, Using the following code Hashtable myData = Hashtable.Synchronized(new Hashtable()); Then I will be having a main thread that will write to this hashtable, and other n threads that will read and write to this hashtable. In the n threads, when reading and writing, only one thread will be assigned specifically on place in the hashtable.
7
1708
by: J L | last post by:
I have defined a structure private structure FieldInfo dim FieldName as string dim OrdinalPostioin as Integer dim DataType as Type dim Size as Integer end structure I read this information from a DataReader which retrieves schema info
5
8562
by: Mark Rae | last post by:
Hi, In v1.x, I used to use the following code to create a case-insensitive Hashtable: Hashtable MyHashtable = new Hashtable(CaseInsensitiveHashCodeProvider.Default, CaseInsensitiveComparer.Default); In v2, this generates the following warnings:
8
5870
by: Ashish Khandelwal | last post by:
-----See below code, string str = "blair"; string strValue = "ABC"; string str1 = "brainlessness"; string strValue1 = "XYZ"; int hash = str.GetHashCode() ; // Returns 175803953 int hash1 = str1.GetHashCode(); // Returns 175803953 Hashtable ht = new Hashtable(); ht.Add(hash ,strValue); ht.Add(hash1,strValue1); // ****ERROR****
0
9714
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9594
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10350
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10096
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9174
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6866
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5673
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4311
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3834
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.