マップを定義し、オブジェクト内に配置します。内部のキーを変更したいのですが、変更方法の値は?コードは次のとおりです。
package maptest;
/**
* test Map
*
* @author admin
*@version 2012.8.29
*/
public class TestA {
private String name;
private String password;
private String idnum;
// name.
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
// password
public void setPassword(String password) {
this.password = password;
}
public String getPassword() {
return password;
}
// idnum
public void setIdnum(String idnum) {
this.idnum = idnum;
}
public String getIdnum() {
return idnum;
}
}
===========================================================
package maptest;
import java.util.HashMap;
import java.util.Map;
/**
* Test Map
*
* @author admin
*@version 2012.8.29
*/
public class TestB {
Map<Object, Object> map = new HashMap<Object, Object>();// map.
public void show() {
TestA tes = new TestA();
tes.setName("a");// name
tes.setPassword("a123");// password
tes.setIdnum("01");// idnum
map.put(tes, tes);// add map.
TestA tes1 = new TestA();
tes1.setName("b");// name
tes1.setPassword("a1234");// password
tes1.setIdnum("02");// idnum
/*
* Assuming in accordance setIdnum ("02"), how to delete the name and
* password of it belongs to?
*/
map.put(tes1, tes1);// add map.
TestA tes2 = new TestA();
tes2.setName("c");// name
tes2.setPassword("a12345");// password
tes2.setIdnum("03");
/*
* Assuming in accordance setIdnum ("03") to find the name and password,
* and then modify one of the password, concrete should be how to
* achieve?
*/
map.put(tes2, tes2);// add map.
}
public void showmap() {// show map
for (Object c : map.keySet()) {
System.out.println("Name>>>:" + ((TestA) map.get(c)).getName());
System.out.println("Password>>>:"
+ ((TestA) map.get(c)).getPassword());
System.out.println("Idnum>>>:" + ((TestA) map.get(c)).getIdnum());
System.out.println("---------------------");
}
System.out.println("end.");
}
public static void main(String[] args) {
// TODO Auto-generated method stub
TestB te = new TestB();
te.show();
te.showmap();
}
}
==========================================
リストと設定の削除と変更とマップ?