阳哥,让我挨个做完题目,挣技术分
- package exam29;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.Iterator;
- import java.util.List;
- import java.util.Map;
- import java.util.Set;
- public class Exam28 {
- public static void main(String[] args) {
- Map<Integer, String> map = new HashMap<Integer, String>();
- map.put(1, "90");
- map.put(2, "80");
- map.put(3, "70");
- map.put(4, "60");
- map.put(5, "50");
- map.put(6, "40");
- map.put(7, "30");
- map.put(8, "20");
- map.put(9, "10");
- //该Map是记录key+(int)value以后的新Map
- Map<Integer,String> tempMap = new HashMap<Integer, String>();
- //该list用于记录新Map中50~150的key值
- List<Integer> list = new ArrayList<Integer>();
- Set<Integer> set= map.keySet();
- Iterator<Integer> it = set.iterator();
- while(it.hasNext()){
- Integer key = it.next();
- String value = map.get(key);
- Integer newKey = key + Integer.parseInt(value);
- //新key在50~150之间的记录到list中
- if(newKey>50 && newKey<150){
- list.add(newKey);
- }
- tempMap.put(newKey, value);
- }
- System.out.println("转变后的Map:"+tempMap);
- for(int i=0;i<list.size();i++){
- tempMap.remove(list.get(i));
- }
- System.out.println("删除50~150后的Map:"+tempMap);
-
- }
- }
复制代码
|
|