HashMap基本用法

来源:百度知道 编辑:UC知道 时间:2024/06/18 14:11:06
要用hashMap方法,我一用PUT就出错,帮看看哪里有错啊;最好讲讲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);

break;
case 2:
String codes=JOptionPane.showInputDialog(null

代码如下;
package list;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class MapTest {
public static void main(String[] args) {
Map<String, Employee> staff = new HashMap<String, Employee>();
staff.put("144-25-5464", new Employee("Amy"));
staff.put("567-24-2546", new Employee("Harry"));
staff.put("157-62-7935", new Employee("Gray"));
staff.put("456-62-5527", new Employee("France"));
System.out.println(staff);

staff.remove("567-24-2546");//删除
System.out.println(staff);

staff.put("456-62-5527", new Employee("Bob"));//替换
System.out.println(staff);

System.out.println(staff.get("