| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 808 人关注过本帖
标题:[求助]能不能讲讲关于HashMap的用法
只看楼主 加入收藏
紫色风铃
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2006-7-18
收藏
 问题点数:0 回复次数:1 
[求助]能不能讲讲关于HashMap的用法

今天做了一个关于HashMap的题目
已经把ArrayList的做出来了要改成HashMap的
import javax.swing.*;
import java.util.*;
public class StudetHashMap{


public static void main(String args[])
{
HashMap stu=new HashMap();


System.out.println ("欢迎进入学生系统");
System.out.println ("1.添加学生");
System.out.println ("2.查询学生");
System.out.println ("3.删除学生");
int c=0;
do
{

int choice=Integer.parseInt(JOptionPane.showInputDialog(null,"请输入你的选择"));

switch(choice)
{
case 1:
Student newstu=null;
String code=JOptionPane.showInputDialog(null,"请你输入学号");

String name=JOptionPane.showInputDialog(null,"请你输入姓名");
newstu=new Student(code,name);
arr.add(newstu);
break;
case 2:
String codes=JOptionPane.showInputDialog(null,"请你输入学号");
Student temp=null;
for (int i = 0; i<stu.size(); i++)
{
temp=(Student)stu.get(i);
if(temp.getCode().equals(codes))
{
break;
}
}
System.out.println (temp.getName());

break;
case 3:

String codee=JOptionPane.showInputDialog(null,"请输入学号");

Student temps=null;
int i=0;
for ( i = 0; i<stu.size(); i++)
{
temps=(Student)stu.get(i);
if(temps.getCode().equals(codee))
{
break;
}
}
stu.remove(i);

}
c=Integer.parseInt(JOptionPane.showInputDialog(null,"继续吗?1.继续\n2.不继续"));

}while(c==1);
}
}

class Student
{
private String name;
private String code;
public Student(String code,String name)
{
this.name=name;
this.code=code;
}
public void setCode(String code)
{
this.code=code;
}
public void setName(String name)
{
this.name=name;
}
public String getName()
{
return name;
}
public String getCode()
{
return code;
}
}

搜索更多相关主题的帖子: HashMap 用法 
2006-08-22 17:47
sunnyxue
Rank: 1
等 级:新手上路
帖 子:62
专家分:0
注 册:2004-12-13
收藏
得分:0 
把student类变成一个hashmap就行了。
另:输入姓名跟学号放在一个JOptionPane里就可以了。

2006-08-23 15:36
快速回复:[求助]能不能讲讲关于HashMap的用法
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015980 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved