前几天面试支付宝,有个基础笔试题,都做错了,题目如下
package com.yf.test;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
public class TreeMapTest {
public static void main(String[] args) {
Map<String,Person> map=new TreeMap<String,Person>();
map.put("tom", new Person(16));
map.put("jim", new Person(17));
map.put("zose", new Person(18));
for(Map.Entry<String, Person> entry:map.entrySet()){
if(entry.getKey().equals("tom")){
map.remove("tom");
System.out.println("find tom");
}
else{
System.out.println(entry.getValue().getAge());
}
}
System.out.println(map.size());
}
}
class Person{
int age;
public Person(int age){
this.age=age;
}
public int getAge(){
return age;
}
}
要求写出程序输出,
该题目本人仅知道TreeMap是基