Map hm = new HashMap();hm.put("key1","key1");hm.get("key1");
解决方案 »
- linux 多线程 主线程退出 主线程创建的线程一起退出? 急!!
- 如何把数据写入Excel的多个Sheet ?
- 请问 javax.xml 与 org.w3c.xml的区别
- 请确认Robot设置鼠标位置在windows远程桌面环境下无效!!!
- 有关进度条的问题
- 把JDesktopPane加到JScrollPane里时,把JDesktopPane拉小点.怎么不显示滚动条啊
- 处理xml文件的问题
- java里面支持的声音文件格式有哪些?????????
- JNI 里无法创建 JVM有什么原因?
- 关于swing的问题
- getContentPane().问题
- [SWT]向StyledText中append()时,为什么会抛出这个异常??
import java.util.Map;
import java.util.HashMap;
import java.util.Iterator;public class HashMapExample
{
public static void main( String[] args )
{
// Create a new HashMap
Map map = new HashMap(); // Add Items to the HashMap
map.put( new Integer( 1 ), "One" );
map.put( new Integer( 2 ), "Two" );
map.put( new Integer( 3 ), "Three" );
map.put( new Integer( 4 ), "Four" );
map.put( new Integer( 5 ), "Five" );
map.put( new Integer( 6 ), "Six" );
map.put( new Integer( 7 ), "Seven" );
map.put( new Integer( 8 ), "Eight" );
map.put( new Integer( 9 ), "Nine" );
map.put( new Integer( 10 ), "Ten" ); // Use iterator to display the keys and associated values
System.out.println( "Map Values Before: " );
Set keys = map.keySet();
for( Iterator i=keys.iterator(); i.hasNext(); )
{
Integer key = ( Integer )i.next();
String value = ( String )map.get( key );
System.out.println( key + " = " + value );
} // Remove the entry with key 6
System.out.println( "\nRemove element with key 6" );
map.remove( new Integer( 6 ) ); // Use iterator to display the keys and associated values
System.out.println( "\nMap Values After: " );
keys = map.keySet();
for( Iterator i=keys.iterator(); i.hasNext(); )
{
Integer key = ( Integer )i.next();
String value = ( String )map.get( key );
System.out.println( key + " = " + value );
}
}
}
一个hashmap的例子