Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java EE 综合讨论区 » J2EE SDK  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 [求助]HashMap的用法!
charm_888





发贴: 8
积分: 1
于 2006-04-14 10:55 user profilesend a private message to usersend email to charm_888search all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
HashMap到底是怎么一回事阿,他的数据结构是什么样子的!
遍历这个hashmap用什么方法啊!

package bag;
import java.util.*;

class Hash
{
  Hash()
  {
HashMap hash=new HashMap();
hash.put("001","北京");
hash.put("002","上海");
hash.put("003","天津");
Iterator it=hash.keySet().iterator();//这是什么意思?Sad
while(it.hasNext())
{
System.out.println("it.Next数据是:"+it.next());
}

}


}



++++++++++++++++++++++++++++++++
人生的路很短暂,又没有回头的机会。所以我愿意朋友们共勉,将路走的更精彩…
http://www.9258.ik8.com
作者 Re:[求助]HashMap的用法! [Re:charm_888]
why

問題兒童

总版主


发贴: 4629
积分: 388
于 2006-04-15 12:23 user profilesend a private message to usersend email to whysearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
> HashMap到底是怎么一回事阿,他的数据结构是什么样子的!
http://en.wikipedia.org/wiki/Hash_table

> 遍历这个hashmap用什么方法啊!
> Iterator it=hash.keySet().iterator();//这是什么意思?
http://java.sun.com/j2se/1.4.2/docs/api/java/util/HashMap.html



作者 Re:[求助]HashMap的用法! [Re:charm_888]
hayash





发贴: 8
积分: 0
于 2006-06-23 23:16 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
package bag;
import java.util.*;
//HashMap 中存放的是键值对,可以通过键直接取得其值。
class Hash
{
Hash()
{
HashMap hash=new HashMap();
hash.put("001","北京");//“001”为键,“北京”为值。
hash.put("002","上海");
hash.put("003","天津");
Iterator it=hash.keySet().iterator();//这是取得键对象
while(it.hasNext())
{
System.out.println("it.Next数据的值是:"+get(it.next())); //获得键所对应的值。
}

}

}



作者 Re:[求助]HashMap的用法! [Re:charm_888]
tiger_hlq





发贴: 9
积分: 0
于 2008-09-12 10:54 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
容器分为三种,List,Set,Map
其中List ,Set 为Collection的实现,而ArrayList又为List接口的实现。HasMap和HasTable都是Map的实现,但是推荐用HasMap,HasTable是java1容器中古老的东西,嘿嘿。
Collection Map
| |
|------------------------| HasMap,TreeMap,HashTable
List Set
| |
ArrayList,LinkList HasSet,TreeSet




flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923