Hi,
i need one help in HashTable. see the below example
[CODE=java]/*
* HashTableTest.j ava
*
* Created on October 20, 2007, 12:48 PM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package kcbchatapplicat ion;
import java.util.Hasht able;
import java.util.Itera tor;
/**
*
* @author nagaraj
*/
public class HashTableTest {
/** Creates a new instance of HashTableTest */
private static Hashtable table;
public HashTableTest() {
table=new Hashtable();
}
private void AddTwo()
{
table.put("firs t","First");
table.put("seco nd","Second") ;
}
private void AddThree()
{
table.put("thre e","Three");
}
public static void main(String a[])
{
HashTableTest test=new HashTableTest() ;
test.AddTwo();
// Enumeration en=table.elemen ts();
for (Iterator it=table.keySet ().iterator(); it.hasNext(); ) {
Object key = it.next();
Object value = table.get(key);
System.out.prin tln("Values:" +value.toString ());
}
test.AddThree() ;
for (Iterator it1=table.keySe t().iterator(); it1.hasNext(); ) {
Object key = it1.next();
Object value = table.get(key);
System.out.prin tln("Values:" +value.toString ());
}
/* while(en.hasMor eElements())
{
System.out.prin tln("Values:" +en.nextElement ().toString());
}
test.AddThree() ;
Enumeration en1=table.eleme nts();
while(en1.hasMo reElements())
{
System.out.prin tln("Values:" +en1.nextElemen t().toString()) ;
}*/
}
public Hashtable getTable() {
return table;
}
}[/CODE]
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
i need one help in HashTable. see the below example
[CODE=java]/*
* HashTableTest.j ava
*
* Created on October 20, 2007, 12:48 PM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package kcbchatapplicat ion;
import java.util.Hasht able;
import java.util.Itera tor;
/**
*
* @author nagaraj
*/
public class HashTableTest {
/** Creates a new instance of HashTableTest */
private static Hashtable table;
public HashTableTest() {
table=new Hashtable();
}
private void AddTwo()
{
table.put("firs t","First");
table.put("seco nd","Second") ;
}
private void AddThree()
{
table.put("thre e","Three");
}
public static void main(String a[])
{
HashTableTest test=new HashTableTest() ;
test.AddTwo();
// Enumeration en=table.elemen ts();
for (Iterator it=table.keySet ().iterator(); it.hasNext(); ) {
Object key = it.next();
Object value = table.get(key);
System.out.prin tln("Values:" +value.toString ());
}
test.AddThree() ;
for (Iterator it1=table.keySe t().iterator(); it1.hasNext(); ) {
Object key = it1.next();
Object value = table.get(key);
System.out.prin tln("Values:" +value.toString ());
}
/* while(en.hasMor eElements())
{
System.out.prin tln("Values:" +en.nextElement ().toString());
}
test.AddThree() ;
Enumeration en1=table.eleme nts();
while(en1.hasMo reElements())
{
System.out.prin tln("Values:" +en1.nextElemen t().toString()) ;
}*/
}
public Hashtable getTable() {
return table;
}
}[/CODE]
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
Comment