1:
(user.age==this.age?
0:
-1);
if(res==0){
inta=(int)this.salary;
intb=(int)user.salary;
if(a>b){
return1;
}elseif(a==b){
{
intrdd=pareTo(user.name);//为什么更换变量之后会改变自然排列顺序,先初始变量,再后来变量
returnrdd;
}
}else{
return-1;
}
}
returnres;
}
10.1替换原映射,2新建映射,3只能移除key值,4返回指定键所映射的值;5如果此映射不包含该键的映射关系,则返回null。
6指定key值,7返回指定键所映射的值,
8keySet()9.返回此映射中包含的键的Set视图,10.values()11.返回此映射中包含的值的Collection视图。
12.entrySet()方法,13.返回此映射中包含的映射关系的Set视图。
11importjava.util.HashMap;
importjava.util.Map;
publicclassx{
publicstaticvoidmain(Stringargs[]){
Mapjjj1=newHashMap();
jjj1.put("1990","xide");
jjj1.put("1994","baxi");
jjj1.put("1998","faguo");
System.out.println("第一次测试");
Stringyear="2005";
System.out.println("输入变量为year,"+year);
if(jjj1.containsKey(year)==true){System.out.println(jjj1.get(year));}else{System.out.println("没有举办世界杯。
");}
System.out.println("第二次测试");
year="1998";
System.out.println("输入变量为year,"+year);
if(jjj1.containsKey(year)==true){System.out.println(jjj1.get(year));}else{System.out.println("没有举办世界杯。
");}
}
}
12
importjava.util.HashMap;
importjava.util.Iterator;
importjava.util.Map;
importjava.util.Map.Entry;
publicclassx{
publicstaticvoidmain(Stringargs[]){
System.out.println("=================");
System.out.println("第一次测试课程安排");
Mapjjj1=newHashMap();
jjj1.put("老师","课程");
jjj1.put("Tom","CoreJava");
jjj1.put("John","Oracle");
jjj1.put("Susan","Oracle");
jjj1.put("Jerry","JDBC");
jjj1.put("Jim","Unix");
jjj1.put("kevin","JSP");
jjj1.put("Lucy","JSP");
System.out.println(jjj1.entrySet());
System.out.println("=================");
System.out.println("第2次测试增加一个老师Allen教JDBC");
jjj1.put("Allen","JDBC");
System.out.print(jjj1.entrySet());
System.out.println("=================");
System.out.println("第3次测试增加Lucy改为教CoreJava");
jjj1.put("Lucy","CoreJava");
System.out.print(jjj1.entrySet());
System.out.println("=================");
System.out.println("第4次测试遍历Map,输出所有的老师及老师教授的课程");
System.out.print(jjj1.entrySet());
System.out.println("=================");
System.out.println("第5次测试利用Map,输出所有教JSP的老师。
");
1510
50
30
16A
17packageuser;
publicclassAddrress{
Stringadrressname;
StringzipCode;
@Override
publicStringtoString(){
return"[adrressname="+adrressname+",zipCode="+zipCode+"]";
}
publicStringgetAdrressname(){
returnadrressname;
}
publicvoidsetAdrressname(Stringadrressname){
this.adrressname=adrressname;
}
publicStringgetZipCode(){
returnzipCode;
}
publicvoidsetZipCode(StringzipCode){
this.zipCode=zipCode;
}
}
packageuser;
importjava.util.*;
publicclassWorker{
privateintage;
privateStringname;
privatedoublesalary;
privateStringadress;
Addrressadrress=newAddrress();
@Override
publicStringtoString(){
returnname+"[age="+age+",name="+name+",salary="+salary+",adrress"+adrress+"]";
}
publicWorker(){}
publicWorker(Stringname,intage,doublesalary,Addrressadrress){
this.name=name;
this.age=age;
this.salary=salary;
this.adrress=adrress;
}
publicintgetAge(){
returnage;
}
publicvoidsetAge(intage){
this.age=age;
}
publicStringgetName(){
returnname;
}
publicvoidsetName(Stringname){
this.name=name;
}
publicdoublegetSalary(){
returnsalary;
}
publicvoidsetSalary(doublesalary){
this.salary=salary;
}
publicvoidwork(){
System.out.println(getName()+"work");}
@Override
publicbooleanequals(Objectobj){
Workeruser1=newWorker();
user1=(Worker)obj;
if(obj!
=null){
//第二步进行比较属性值是否相等
returnthis.name.equals(user1.name)&&this.age==(user1.getAge());
}
returntrue;}
@Override
publicinthashCode(){
intresult=0;
if(name!
=null){result=name.hashCode();}
returnresult+age;
//TODOAuto-generatedmethodstub
//returnsuper.hashCode();
}}
18packageuser;
importjava.util.HashMap;
importjava.util.Map;
publicclassfootball{
publicstaticvoidmain(Stringargs[]){
Mapjjj1=newHashMap();
jjj1.put("1990","xide");
jjj1.put("1994","baxi");
jjj1.put("2002","faguo");
jjj1.put("1998","faguo");
jjj1.put("2006","faguo");
jjj1.put("2010","faguo");
System.out.println("第一次测试");
Stringyear="2005";
System.out.println("输入变量为year,"+year);
if(jjj1.containsKey(year)==true){System.out.println(jjj1.get(year));}else{System.out.println("没有举办世界杯。
");}
System.out.println("第二次测试");
year="1998";
System.out.println("输入变量为year,"+year);
System.out.println(jjj1.get("henan"));//荷兰还没夺过冠.
if(jjj1.containsKey(year)==true){System.out.println(jjj1.get(year));}else{System.out.println("没有举办世界杯。
");}
Stringqiudui="henan";
if(jjj1.containsValue(qiudui)==true){System.out.println(qiudui+"夺过冠");}else{System.out.println(qiudui+"未夺过世界杯。
");}
}
}
19
packageuser;
importjava.util.*;
publicclassTestAccout{
publicstaticvoidmain(String[]args){
Listlist=newArrayList();
list.add(newAccount(10.00,"1234"));
list.add(newAccount(15.00,"5678"));
list.add(newAccount(0,"1010"));
Mapjjj=newHashMap();
Accountaa=newAccount();
Listlist1=newArrayList();
for(inti=0;ijjj.put(list1,list);
System.out.println(jjj.entrySet());
}
}
packageuser;
publicclassAccount{
longID;
doublebalance;
Stringpassword;
Account(){}
Account(doublebalance,Stringpassword){this.balance=balance;this.password=password;}
publiclonggetID(){
returnID;
}
publicvoi