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;
/*
Set keys1 = map.keySet();
Set keys2 = map.keySet();
Set keys3 = map.keySet();
上面三个set对象key1,key2,key3引用的是一个对象。
这是map的keySet()方法只返回一个set实例,所以当从key1中删除一个对象时候,
key2和key3将会受到影响。 */
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 iterator = map.keySet().iterator(); //keySet() 返回此映射中包含的键的 Set 视图。
//iterator()返回在此 set 中的元素(这里是key值)上进行迭代的迭代器。
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 assertionsProcess 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;
/*
Set keys1 = map.keySet();
Set keys2 = map.keySet();
Set keys3 = map.keySet();
上面三个set对象key1,key2,key3引用的是一个对象。
这是map的keySet()方法只返回一个set实例,所以当从key1中删除一个对象时候,
key2和key3将会受到影响。 */
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 iterator = map.keySet().iterator(); //keySet() 返回此映射中包含的键的 Set 视图。
//iterator()返回在此 set 中的元素(这里是key值)上进行迭代的迭代器。
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 assertionsProcess completed.
解决方案 »
- 帮忙求一个程序运行的结果
- JAVA Canvas画布不画的图形会自动消失,是什么原因,怎样让它不消失?
- 新手:JDBC连接oracle问题(在线等)
- class Hen implements A{}没有实现Protectable呀那为什么它里面可以有public void beProtected()『』?
- 如何构建一个可用于密码输入的文本框
- 小弟想问一个关于JAVA初学者的问题,我的分也不是很多,给50吧
- 如何处理wmv文件
- 大家有没有在用 jb 7 ??
- about jdk(12)
- 主函数中的for循环时,每一个node都会分配一个nextNode吗?可是nextNode是成员变量,只有一个没有new啊!求解
- 初学java的看过来~~~~
- JavaScript缩放加拖动
我对你的程序进行了分析,也没有发现什么错误,你再试一下,看有没有其他方面的原因,或者是你引入的包有问题