import java.util.Map;
import java.util.HashMap;
import java.util.Set;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Hashtable;
import java.util.TreeMap;
class HashMaps
{
public static void main(String[]args)
{
Map map=new HashMap();
map.put("a", "aaa");
map.put("b", "bbb");
map.put("c", "ccc");
map.put("d", "ddd");
map.put("e","eee");
//System.out.println(map.size());//public int size()返回此映射中的键-值映射关系数。
System.out.println( map.get("e"));//get()方法的参数是key 类型,是根据key值来决定结果输出eee
Set key1 = map.keySet();
Set key2 = map.keySet();
Set key3 = map.keySet();
System.out.println(key1);
System.out.println(key2);
System.out.println(key3);
/*
这段代码输出
[d, a, c, b, e]
[d, a, c, b, e]
[d, a, c, b, e]
*/
Iterator iterator = map.keySet().iterator();
while (iterator.hasNext()) {
Object key = iterator.next();
System.out.println(key);
System.out.println("map.get(key) is :"+map.get(key));
}
}
}
为什么会出现这种错误啊 一开始调试的时候还行的啊
在没加入System.out.println(map.size());这句话之前还行的啊 加入之后将他注释也不行
我用的是jcreator
--------------------Configuration: <Default>--------------------
Usage: java [-options] class [args...]
(to execute a class)
or java [-options] -jar jarfile [args...]
(to execute a jar file) where options include:
-client to select the "client" VM
-server to select the "server" VM
-hotspot is a synonym for the "client" VM [deprecated]
The default VM is client.
-cp <class search path of directories and zip/jar files>
-classpath <class search path of directories and zip/jar files>
A ; separated list of directories, JAR archives,
and ZIP archives to search for class files.
-D <name>= <value>
set a system property
-verbose[:class|gc|jni]
enable verbose output
-version print product version and exit
-version: <value>
require the specified version to run
-showversion print product version and continue
-jre-restrict-search | -jre-no-restrict-search
include/exclude user private JREs in the version search
-? -help print this help message
-X print help on non-standard options
-ea[: <packagename>...|: <classname>]
-enableassertions[: <packagename>...|: <classname>]
enable assertions
-da[: <packagename>...|: <classname>]
-disableassertions[: <packagename>...|: <classname>]
disable assertions
-esa | -enablesystemassertions
enable system assertions
-dsa | -disablesystemassertions
disable system assertions Process completed.
import java.util.HashMap;
import java.util.Set;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Hashtable;
import java.util.TreeMap;
class HashMaps
{
public static void main(String[]args)
{
Map map=new HashMap();
map.put("a", "aaa");
map.put("b", "bbb");
map.put("c", "ccc");
map.put("d", "ddd");
map.put("e","eee");
//System.out.println(map.size());//public int size()返回此映射中的键-值映射关系数。
System.out.println( map.get("e"));//get()方法的参数是key 类型,是根据key值来决定结果输出eee
Set key1 = map.keySet();
Set key2 = map.keySet();
Set key3 = map.keySet();
System.out.println(key1);
System.out.println(key2);
System.out.println(key3);
/*
这段代码输出
[d, a, c, b, e]
[d, a, c, b, e]
[d, a, c, b, e]
*/
Iterator iterator = map.keySet().iterator();
while (iterator.hasNext()) {
Object key = iterator.next();
System.out.println(key);
System.out.println("map.get(key) is :"+map.get(key));
}
}
}
为什么会出现这种错误啊 一开始调试的时候还行的啊
在没加入System.out.println(map.size());这句话之前还行的啊 加入之后将他注释也不行
我用的是jcreator
--------------------Configuration: <Default>--------------------
Usage: java [-options] class [args...]
(to execute a class)
or java [-options] -jar jarfile [args...]
(to execute a jar file) where options include:
-client to select the "client" VM
-server to select the "server" VM
-hotspot is a synonym for the "client" VM [deprecated]
The default VM is client.
-cp <class search path of directories and zip/jar files>
-classpath <class search path of directories and zip/jar files>
A ; separated list of directories, JAR archives,
and ZIP archives to search for class files.
-D <name>= <value>
set a system property
-verbose[:class|gc|jni]
enable verbose output
-version print product version and exit
-version: <value>
require the specified version to run
-showversion print product version and continue
-jre-restrict-search | -jre-no-restrict-search
include/exclude user private JREs in the version search
-? -help print this help message
-X print help on non-standard options
-ea[: <packagename>...|: <classname>]
-enableassertions[: <packagename>...|: <classname>]
enable assertions
-da[: <packagename>...|: <classname>]
-disableassertions[: <packagename>...|: <classname>]
disable assertions
-esa | -enablesystemassertions
enable system assertions
-dsa | -disablesystemassertions
disable system assertions Process completed.
我的系统为jdk6
不加keySet()也可以