hashmap and hashset in java
how to
convert a hashtable to
hashmap and print in the order which i entered.
using java
Software
how to
convert a hashtable to
hashmap and print in the order which i entered.
using java
by rajagitam Accepted solution
by cdumitru Accepted solution
This can be done using a LinkedHashMap, a brother of HashMap, implementing the same Map interface.
The code is written for JDK 5, but LinkedHashMap exists from JDK 1.4:
public Map convert( Hashtable table )
{
if( table == null ) return null;
Map map = new LinkedHashMap( table.size() );
for( Map.Entry entry: table.entrySet() )
{
map.put( entry.getKey(), entry.getValue() );
}
return map;
}
public void print( Hashtable table )
{
Map map = convert( table );
System.out.println( map );
}
This discussion is closed to new replies.
Sort by Trending